Welcome to Dream.In.Code
Become an Expert!

Join 149,602 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,896 people online right now. Registration is fast and FREE... Join Now!




Assembly Language: Homework Problem

 
Reply to this topicStart new topic

Assembly Language: Homework Problem, Assembly Language

vyiruskiller
13 Oct, 2007 - 02:58 PM
Post #1

New D.I.C Head
*

Joined: 4 Oct, 2006
Posts: 14


My Contributions
Hi, i am an english student studying in mexico. Our teacher gave us a program in Assembly Language to make corrections, compile and explain. I made the necessary corrections and, I tried compiling the program but i received an error " C:\WINDOWS\system32\cmd.exe-examen21
The NTVDM CPU has encountered an illegal instruction.
CS:0000 IP:415d OP:ff ff ff ff ff Choose 'Close' to terminate the applicacion.
"

Can you please help me with what might be this error i am encountering.
THE CODE IS INCLUDED BELOW.


CODE

TITLE    P21MOUSE (EXE)    USE OF THE MOUSE
    .MODEL    SMALL
    .STACK    64
    .DATA

XBINARY        DW    0;COORDINATE X BINARY
YBINARY        DW    0;COORDINATE Y BINARY
ASCVAL        DW    ?;VARIABLE ASCII

;-------variables

DISPDATA    LABEL    BYTE
XMSG        DB    'X = ';MESSAGE X
XASCII        DW    ?;ASCII VALUE OF X
        DB    ' '
YMSG        DB    'Y = ';MESSAGE Y
YASCII        DW    ?;ASCII VALUE OF Y

    .CODE

BEGIN    PROC    FAR
    MOV    AX,@data;START
    MOV    DS,AX    ;EL REGISTRO DS
    CALL    Q10CLEAR;CLEAR SCREEN
    CALL     B10INIT    ;INICIALIZA EL RATON
    CMP    AX,00    ;¿RATON INSTALADO?
    JE    A90    ;NO,EXIT
A10:
    CALL    D10PTR    ;OBTENER APUNTADOR DEL RATON
    CMP    BX,01    ;¿BOTON PRESIONADO?
    JE    A80    ;SI, SALIR
    CALL     Q20CURS    ;COLOCAR EL CURSOR
    MOV    AX,XBINARY;
    CALL    G10CONV    ;X TO ASCII
    MOV    AX,ASCVAL;
    MOV    XASCII,AX;
    MOV    AX,YBINARY;
    CALL    G10CONV    ;Y TO ASCII
    MOV    AX,ASCVAL;
    CALL    Q30DISP    ;DISPLAY VALUES OF X & Y
    JMP    A10    ;REPETIR
A80:
    CALL    H10HIDE    ;HIDE MOUSE POINTER
A90:
    CALL    Q10CLEAR;CLEAR SCREEN
    MOV    AX,4C00H;EXIT TO DOS
    INT    21H
BEGIN    ENDP
B10INIT    PROC    NEAR
    MOV    AX,00H    ;INICIALIZAR EL RATON
    INT    33H
    CMP    AX,00    ;¿RATON INSTALADO?
    JE    B90    ;NO,SALIR
    MOV    AX,01H    ;MOSTRAR APUNTADOR
B90:
    RET        ;REGRESAR A DONDE FUE LLAMADO    
B10INIT    ENDP

.286
D10PTR    PROC    NEAR
D20:    MOV    AX,03H    ;OBTENER POSICION DE APUNTADOR
    INT     33H
    CMP    BX,01    ;¿BOTON DERECHO PRESIONADO?
    JE    D90    ;SI,SIGNIFICA SALIR
    SHR    CX,03    ;DIVIDIR EL NUMERO DE PIXEL
    SHR    DX,03    ;ENTRE 8
    CMP    CX,XBINARY;¿HA CAMBIADO LA POSICION
    JNE    D30    ;DEL APUNTADOR?
    CMP    DX,YBINARY;
    JE    D20    ;NO, REPETIR LA OPERACION
D30:                
            ;SI
    MOV    XBINARY, CX;GUARDAR LA NUEVA POSICION
    MOV    YBINARY, DX;
D90:
    RET        ;REGRESAR A DONDE FUE LLAMADO
D10PTR    ENDP

G10CONV    PROC    NEAR    ;AX = X O Y BINARIO
    MOV    ASCVAL,2020H;LIMPIA EL CAMPO ASCII
    MOV    CX,10    ;FIJA EL FACTOR DE DIVISION
    LEA    SI,ASCVAL+1;CARGA LA DIRECCION ASCVAL
    CMP    AX,CX    ;COMPARA LA POSICION CON 10
    JB    G30    ;MENOR, PASAR
    DIV    CL    ;MAYOR, DIVIDIR ENTRE 10
    OR    AH,30H    ;INSERTAR 3 ASCII
    MOV    [SI],AH    ;ALMACENAR EN EL BYTE DE LA DERECHA
    DEC    SI    ;DISMINUIR DIRECCION DE ASCVAL
G30:
    OR    AL,30H    ;INSERTAR 3 ASCII
    MOV    [SI],AL    ;ALMACENAR EN EL BYTE MAS A LA IZQUIERDA
    RET        ;REGRESAR A DONDE FUE LLAMADO
G10CONV    ENDP

H10HIDE    PROC    NEAR        
    MOV    AX,02H    ;OCULTAR APUNTADOR
    INT    33H
    RET        ;REGRESAR A DONDE FUE LAMADO
H10HIDE    ENDP

Q10CLEAR PROC    NEAR    
    MOV    AX,0600H;PETICION PARA LIMPIAR LA PANTALLA
    MOV    BH,30H    ;COLORES
    MOV    CX,00    ;PANTALLA
    MOV    DX,184FH;COMPLETA
    INT     10H
    RET        ;REGRESAR A DODNE FUE LLAMADO
Q10CLEAR ENDP

Q20CURS    PROC    NEAR
    MOV    AH,02H    ;COLOCAR CURSOR
    MOV    BH,00    ;PAGINA 0
    MOV    DH,0    ;RENGLON
    MOV    DL,25    ;COLUMNA
    INT    10H                
    RET        ;REGRESAR A DONDE FUE LLAMADO
Q20CURS    ENDP    

Q30DISP    PROC    NEAR    
    MOV    AX,40H    ;PETICION PARA DESPLEGAR
    MOV    BX,01    ;PANTALLA
    MOV    CX,14    ;NUMERO DE CARACTERES
    LEA    DX,DISPDATA;AREA DE DESPLIEGUE
    INT     21H    
    RET        ;REGRESAR A DONDE FUE LLAMADO
Q30DISP    ENDP
    END    BEGIN
    





User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Assembly Language: Homework Problem
13 Oct, 2007 - 08:56 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,869



Thanked: 53 times
Dream Kudos: 550
My Contributions
Nitpicking first: You don't 'compile' an assembly language routine, you assemble it.

how did you assemble the program (what assembler did you use?)
User is online!Profile CardPM
+Quote Post

vyiruskiller
RE: Assembly Language: Homework Problem
13 Oct, 2007 - 09:00 PM
Post #3

New D.I.C Head
*

Joined: 4 Oct, 2006
Posts: 14


My Contributions
I used Turbo assembler (TASM). That is assembler the class is allowed to use. Sorry of using the word compile. Thanks for the correction

QUOTE(NickDMax @ 13 Oct, 2007 - 09:56 PM) *

Nitpicking first: You don't 'compile' an assembly language routine, you assemble it.

how did you assemble the program (what assembler did you use?)


User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Assembly Language: Homework Problem
14 Oct, 2007 - 01:32 PM
Post #4

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,026



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
The Crash occurs after the INT 21h is called in this procedure:
CODE
Q30DISP    PROC    NEAR    
    MOV    AX,40H   ;PETICION PARA DESPLEGAR
    MOV    BX,01   ;PANTALLA
    MOV    CX,14   ;NUMERO DE CARACTERES
    LEA    DX,DISPDATA;AREA DE DESPLIEGUE
    INT     21H    
    RET       ;REGRESAR A DONDE FUE LLAMADO
Q30DISP    ENDP

It's been a while since I did 16-bit assembly.
I don't quite remember what function 40h value in AX does (I'm not even close to any documentation), but I can tell that one of your parameters (in registers AX,BX,CX or DX) is incorrect or incomplete. Check if you've got them all right.

I've also noticed that you use this instruction a lot:
CODE
MOV <register> , 0

Depending on the system architecture, this instruction can even take up more than 6 bytes.

Use a XOR instruction instead like this:
CODE
XOR <register> , <register>

This takes up only 2 bytes. Remember that the result of XORing any number with itself is always zero.

Another one is:
CODE
CMP <register> , 0

Some assembly coders (including me wink2.gif) prefer to use the DEC instruction instead of the CMP <REG>X , 0 instruction; as it takes up just one byte (for 16bit registers such as AX, decrementing AH takes up 2 bytes)

Here's how it works:
If a number is zero, decrementing it would result in the number being set to -1. This triggers the ZF which can be tested with a JZ instruction.
It is complicated, but that's a price you have to pay for short and fast code.

Since you're doing this as a school assignment, using CMP is okay.

P.S : I hope you know that you haven't passed the right parameters to clear the screen. From what I've seen, your code will turn the background Blue.

You can refer to the Assembly Code Snippet that I wrote (right now for you) that clears the screen.
User is online!Profile CardPM
+Quote Post

Louisda16th
RE: Assembly Language: Homework Problem
16 Oct, 2007 - 05:37 AM
Post #5

 101010101
Group Icon

Joined: 3 Aug, 2006
Posts: 1,812



Thanked: 1 times
Dream Kudos: 755
My Contributions
Can you use this in C/C++ (inline Assembly)? I mean, it will be OS independent right? smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:50PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month