-2

:) I am struggling with a piece of assembly language, mostly the order in which my strings are printed. Here's what I have!!

.model small
.stack 100h
.DATA


;DISPLAYS

msgquestion db 13,10, "Addition or Subtraction?: $ "  
msgfirst db 13,10, "Enter first number : $"     ;MESSAGE first   
msgsecond db  "Enter second Number : $"         ;MESSAGE second
msgSum db 13,10, "The result is : $"
msgDif db 13,10, "The result is : $"
msgterminator db 13,10, "X to END: $"
.code 

;START OF CODE

start:
    mov ax,@data 
    mov ds, ax

    lea dx, msgfirst  ;Displays first
    mov ah, 09h
    int 21h
    mov bx, 0

start1:
        mov ah, 01h
        int 21h     
        cmp al,0dh      
        je next1
        mov ah,0        
        sub al,30h      
        push ax         
        mov ax,10d      
        mul bx          
        pop bx          
        add bx,ax 
        jmp start1 

next1:
        push bx
        lea dx,msgsecond  ;DISPLAYS MESSAGE 'second'
        mov ah,09h
        int 21h

        mov bx,0

start2:
        mov ah,01h
        int 21h
        cmp al,0dh
        je QUESTION
        mov ah,0
        sub al,30h
        push ax
        mov ax,10d
        mul bx
        pop bx
        add bx,ax 
        jmp start2


    QUESTION:

        lea dx, msgquestion
        mov ah, 09h
        int 21h

        mov ah, 01h
        int 21h

        cmp al,'+'  
        je adding

        cmp al,'-'
        je subtracting

        cmp al,'x'
        mov ah, 4ch
        int 21h
        jmp break


TERMINATOR:

        lea dx, msgterminator
        mov ah, 09h
        int 21h

        mov ah, 01h
        int 21h

        cmp al,'+'  
        je adding

        cmp al,'-'
        je subtracting

        cmp al,'x'
        mov ah, 4ch
        int 21h
        jmp break

adding:     
        pop ax
        add ax,bx   
        push ax
        lea dx,msgSum   
        mov ah,09h
        int 21h 
        pop ax
        mov cx,0
        mov dx,0
        mov bx,10d
        jmp break

subtracting: 
        pop ax
        sub ax,bx 
        push ax
        lea dx,msgDif
        mov ah,09h
        int 21h 
        pop ax
        mov cx,0
        mov dx,0
        mov bx,10d

break:
        div bx
        push dx
        mov dx,0
        inc cx
        or ax,ax 
        jne break 

ans:        
        pop dx
        add dl,30h
        mov ah,02h
        int 21h
        loop ans


    jmp TERMINATOR
    end start

;END OF THE PROGRAM

I would like to get the addition and subtraction QUESTION to display first. Also please suggest any other errors I made! I am really grateful guys, thanks a mil!! <3

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    You've already got code in there to display the `msgfirst` string. Have you tried doing exactly the same thing for `msgquestion`? What happened when you did that? – Michael Sep 09 '13 at 14:26

1 Answers1

0

What I understand from your question is that you wish to display the Addition or subtraction: first and then input your numbers & perform the calculation. Well the solution is simple. As soon as your code begins, you can ask the user the question to add or subtract and then store the saved value (from al) into a variable. Later on you can simply use that saved value for comparison purpose.

Here is the new code

    .model small
.stack 100h
.DATA


;DISPLAYS

msgquestion db 13,10, "Addition or Subtraction?: $ "  
msgfirst db 13,10, "Enter first number : $"     ;MESSAGE first   
msgsecond db  "Enter second Number : $"         ;MESSAGE second
msgSum db 13,10, "The result is : $"
msgDif db 13,10, "The result is : $"
msgterminator db 13,10, "X to END: $"
v1 db ?
.code 

;START OF CODE

main proc
    mov ax,@data 
    mov ds, ax

    ;//CHANGES MADE HERE
    ;//add or sub
    lea dx, msgquestion
    mov ah, 09h
    int 21h

    mov ah, 01h
    int 21h

    mov v1,al
    ;//END CHANGES

    lea dx, msgfirst  ;Displays first
    mov ah, 09h
    int 21h
    mov bx, 0

start1:
        mov ah, 01h
        int 21h     
        cmp al,0dh      
        je next1
        mov ah,0        
        sub al,30h      
        push ax         
        mov ax,10d      
        mul bx          
        pop bx          
        add bx,ax 
        jmp start1 

next1:
        push bx
        lea dx,msgsecond  ;DISPLAYS MESSAGE 'second'
        mov ah,09h
        int 21h

        mov bx,0

start2:
        mov ah,01h
        int 21h
        cmp al,0dh
        je QUESTION
        mov ah,0
        sub al,30h
        push ax
        mov ax,10d
        mul bx
        pop bx
        add bx,ax 
        jmp start2


    QUESTION:

        mov al,v1     ;will now move the value stored in v1 earlier into al for comparision

        cmp al,'+'  
        je adding

        cmp al,'-'
        je subtracting

        cmp al,'x'
        mov ah, 4ch
        int 21h
        jmp break


TERMINATOR:

        lea dx, msgterminator
        mov ah, 09h
        int 21h

        mov ah, 01h
        int 21h

        cmp al,'+'  
        je adding

        cmp al,'-'
        je subtracting

        cmp al,'x'
        mov ah, 4ch
        int 21h
        jmp break

adding:     
        pop ax
        add ax,bx   
        push ax
        lea dx,msgSum   
        mov ah,09h
        int 21h 
        pop ax
        mov cx,0
        mov dx,0
        mov bx,10d
        jmp break

subtracting: 
        pop ax
        sub ax,bx 
        push ax
        lea dx,msgDif
        mov ah,09h
        int 21h 
        pop ax
        mov cx,0
        mov dx,0
        mov bx,10d

break:
        div bx
        push dx
        mov dx,0
        inc cx
        or ax,ax 
        jne break 

ans:        
        pop dx
        add dl,30h
        mov ah,02h
        int 21h
        loop ans


    jmp TERMINATOR
main endp
end main
worriednacho
  • 57
  • 4
  • 15