What does this code do? .model small .386 .stack 100h .data msg1 db 13, 10, "Enter any number --> ", "$" msg2 db "Enter an operation +,- * or / --> ",13, 10, "$" msg3 db "The Operation is --> ", "$" msg4 db "The result is --> ", "$" By_base dd 21 by_10 dd 10 ; 32 bits variable with initial value = 10 sp_counter db 0 ; 8 bits variable with initial value of zero disp_number dd 0 ; 32 bits variable with initial value = 0 disp_number2 dd 0 disp_number3 dd 0 op_type db 0 last_key dd 0 ; 32 bits variable with initial value of zero remainder db 0 .code main proc mov ax,@data ; set up data segment mov ds,ax mov dx,offset msg1 call display_message call m_keyin

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

What does this code do?

 

.model small 
.386 
.stack 100h 

.data 
msg1 db 13, 10, "Enter any number --> ", "$"
msg2 db  "Enter an operation +,- * or /  --> ",13, 10, "$"
msg3 db  "The Operation is --> ", "$"
msg4 db  "The result is --> ", "$"
By_base dd 21
by_10 dd 10  ; 32 bits variable with initial value = 10
sp_counter db 0 ; 8 bits variable with initial value of zero
disp_number dd 0 ; 32 bits variable with initial value = 0
disp_number2 dd 0
disp_number3 dd 0
op_type db 0
last_key dd 0 ; 32 bits variable with initial value of zero
remainder db 0
.code 

main proc
    mov ax,@data ; set up data segment
    mov ds,ax
        mov dx,offset msg1
    call display_message

    call m_keyin
    
    call operation
    mov dx,offset msg1
    call display_message

    call m_keyin
    cmp op_type, "+"
    jnz short skip_plus
    
    call op_plus
    
    skiP_plus:
    cmp op_type, "-"
    jnz short skip_minus
    call op_minus
    
skip_minus:
    
    cmp op_type, "*"
    jnz short skip_mul
    
    call op_mult
    
skip_mul:
cmp op_type, "/"
    jnz short skip_div
    
    call op_div
skip_div:    
    call m_display
mov ax, 4c00h 
int 21h 

operation proc
    mov dx,offset msg2
rpt4:
    call display_message
    mov dx,offset msg3
    call display_message
    mov ah, 1
    int 21h
    cmp al, 30h
    jns rpt4
    mov op_type, al
    
    
ret
operation endp

m_display proc
    mov dx,offset msg4
    call display_message
    mov eax, disp_number
    mov sp_counter, 0    

Base_lp:

LP1:
    mov edx, 0
    div By_Base
    push dx
    inc sp_counter
    cmp eax, 0
    jnz lp1

LP2:
    pop dx
    call display
    dec sp_counter
    jnz lp2
    mov edx, -8
    call display
    mov edx, by_base
    call display
    mov edx, -7
    call display
     dec By_base
    mov eax, disp_number
    cmp By_base, 1
    jnz Base_lp
    
    ret
    
m_display endp

op_minus proc
    mov eax, disp_number2
    sub eax, disp_number3
    mov disp_number, eax
    ret
op_minus endp    
op_div proc

mov eax, disp_number2
div disp_number3
mov disp_number, eax
mov remainder, dl

call display
call m_display
mov dl, -16
call display

mov dl, remainder
call display
mov dl, -1
call display
mov edx, disp_number3

call display


mov ax, 4c00h 
int 21h 
op_div endp

op_mult proc
    mov eax, disp_number2
    mul disp_number3
    mov disp_number, eax

ret
op_mult endp
op_plus proc
    mov eax, disp_number2
    add eax, disp_number3
    mov disp_number, eax
    ret
op_plus endp
display proc
    add dl, 30h
    cmp dl, 3ah
    js short skip_hex
    add dl, 7
Skip_hex:
     
    mov ah, 6
    int 21h
    ret
    display endp

display_message proc
    mov ah, 9 ; to display to screen the string pointed by the DX register.
    int 21h
    mov edx, 0
    ret
display_message endp
    
m_keyin proc
    MOV disp_number, 0
    mov last_key, 0
    LP_key:; location in the program label
    mov eax, disp_number
    mul by_10  ; eax = (eax) * 10
    add eax, last_key
    mov DISP_NUMBER, eax  ; save it to the number to display
    
    mov ah, 1 ; enables a single key entry
    int 21h
    AND eax, 000000ffh
    cmp al, 13 ; compare the key entered to 13 i.e. ascii of CR
    jz short finkey ; if CR was pressed then exit the enter key routine
    sub al, 30h  ; remove the ascii from the number entered to get a pure number.
    MOV LAST_KEY, EAX  ; save the last digit entered
    jmp lp_key  ; unconditional jump to the enter key routine in a loop
    finkey:    
    MOV eax, DISP_NUMBER
    cmp DISP_NUMBER2,0
    jnz short skip
    MOV DISP_NUMBER2, EAX
skip:
    MOV DISP_NUMBER3, EAX
    ret
m_keyin endp


main endp
end main

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random access
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education