Question

In: Computer Science

;the task is to print out the result no matter how many digits ; it should...

;the task is to print out the result no matter how many digits 
; it should work on Emu8086
;the code should be in assembly language 
; add comments to your code



org 100h

.data

F db 0
num1 db 0
num2 db 0
op db 0
result db 0
msg db 0dh,0ah,"Error"


.code
mov ax,@data
mov ds,ax


LL1:
call get1 
cmp ax,0
je print
cmp F,0
je LL1  

LL2:
call get2 
cmp ax,0
je print
cmp F,1
je LL2


Solve: 

cmp op,'+'
je addition
mov bl, num1
sub bl,num2
mov result,bl
jmp printresult
addition:
mov bl, num1
add bl,num2
mov result,bl

printresult:

;Task: add code to print result

jmp done




print:

mov cx,7
mov si,0
screen:
mov dl,msg[si]
mov ah,2
int 21h
inc si
loop screen


done:
ret


get1 proc
     
    mov ah,1
    int 21h
        
    cmp al,'+'
    je L4 
    cmp al,'-'
    je L5
    
    sub al,30h
    
    cmp al,0
    jb L2
    cmp al,9
    ja L2
    
    mov cx,10
    mov bh,0
    L3:
    add bh,num1
    loop L3
    add bh,al
    mov num1,bh
    ret 
    
    L4:
    mov op,'+'
    mov F,1
    ret
    L5:
    mov op,'-'
    mov F,1
    ret
    L2:
    mov ax,0
       
    ret
    endp

get2 proc
     
    mov ah,1
    int 21h
        
    cmp al,'='
    je L41 
    
    
    sub al,30h
    
    cmp al,0
    jb L21
    cmp al,9
    ja L21
    
    mov cx,10
    mov bh,0
    L31:
    add bh,num2
    loop L31
    add bh,al
    mov num2,bh
    ret 
    
    L41:
    mov F,2
    ret
    
    L21:
    mov ax,0
       
    ret
    endp

Solutions

Expert Solution

Greetings!!

  • Only the code for display is added

Code:

.DATA

RES DB 4 DUP(?) ;array to store the decimal result

printresult:
LEA SI,RES ;load the address of result array
ADD SI,2 ;increments the array index by 2 to access the array from last to first
PUSH AX ;saves the previous answers on to the stack
PUSH CX
PUSH DX
  
MOV CL,10 ;load 10 to CL for converting the answer to decimal
MOV AL,BL ;copy the answer into register AL
AGAIN:
MOV AH,0 ;clear AH
DIV CL ;divide the answer with 10 and store the remainder(is the equivalent decinal) into the result array
ADD AH,30H ;add 30H to convert into ASCII
MOV [SI],AH ;store the decimal digit into the array
DEC SI ;decrement array index
CMP AL,0 ;check the convetion is over or not
JZ END ;if finished go to the label END
JMP AGAIN ;otherwise repeat the division process to convert the answer to decimal
END:
LEA SI,RES
MOV [SI+3],'$' ;insert end of string character at the end of the result array
  
MOV DX,OFFSET RES ;display the answer stored in the result array
MOV AH,9
INT 21H
  
POP DX ;reload the registers
POP CX
POP AX

jmp done

Output screenshots:

Hope this helps


Related Solutions

Print out screenshot(s) that show the result of setting the prompt to different values as indicated....
Print out screenshot(s) that show the result of setting the prompt to different values as indicated. Remember that you can change the prompt to include the result of a UNIX command if you include the command name in backquotes. To get credit for each step, you must have the screenshot show the command you used to set the prompt and that it worked as intended. Set the prompt to the UNIX server’s name and an arrow by using the hostname...
How many times should the following C code print "Example" and draw a process graph #include...
How many times should the following C code print "Example" and draw a process graph #include <stdio.h> #include <sys/types.h> #include <unistd.h> void try() { fork(); printf("Example\n"); fork(); return; } int main() { try(); fork(); printf("Example\n"); exit(0); }
Many people are out of work as a result of COVID-19. This means that they will...
Many people are out of work as a result of COVID-19. This means that they will not be paying as much money in taxes so government revenue will decrease. At the same time, the government spending has increased as the government bails out businesses, increases spending on healthcare, and provides income assistance to a growing number of people. How does declining tax revenue and increasing government spending impact the government debt?
how many significant digits does 0.300 have?
how many significant digits does 0.300 have?
in the following arithmetic operation when carried out, how many significant figures should be reported in...
in the following arithmetic operation when carried out, how many significant figures should be reported in the answer and why? (0.523)(1.2161-0.99)+(2.648/0.87)(84-81.98)
1. A) How many three-digit numbers are there for which the sum of the digits is...
1. A) How many three-digit numbers are there for which the sum of the digits is at least 25? B) How many three-digit numbers can be formed if only odd numbers are allowed to be re-used Please combinatorics principles where applicable.
How many grams of each product result from the following reactions, AND how many grams of...
How many grams of each product result from the following reactions, AND how many grams of each reactant is left over? (Shntould be three amounts left over for each equation) 1) ( 1.3 g NaCl)+( 3.2 g AgNO3)→(xgAgCl)+(ygNaNO3) 2) ( 2.63 g BaCl2)+( 6.76 g H2SO4)→(xgBaSO4)+(ygH
How many base 10 numbers have five digits? How many five digit numbers have no two...
How many base 10 numbers have five digits? How many five digit numbers have no two consecutive digits equal? How many have at least one pair of consecutive digits equal?
how many five digit numbers include the digits 4 or 6 or both?
how many five digit numbers include the digits 4 or 6 or both?
A zip code is a string of five digits (0,1,2,3,4,5,6,7,8,9). How many zip codes are there...
A zip code is a string of five digits (0,1,2,3,4,5,6,7,8,9). How many zip codes are there subject to the following restrictions? (1) Only even digits are allowed. (2) The first digital is even and the last digit is odd (3) Digits cannot be repeated (4) 0 appears exactly four times (5) 0 appears at at least once Solve the following discrete mathematics problem above. Show all work/explanations
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT