0

I am given the below program written in asm and it is my understanding that in x i have the sum of n, i ,t and in y i have the sum of l,u and that the z has the value of x and y. I do not know the importance of the loop1 sequence for the printing of the "z" value. Can I output the that value in other ways?

.stack 100h
.data

    n dw 8

    i dw 3 

    t dw 4

    l dw 6

    u dw 5

    x dw ? 
    y dw ? 
    z dw ? 
    nstr db 3 dup(' ')
    idv dw 10
.code
.startup
    mov ax, dgroup
    mov ds, ax 

    mov ax, n  
    add ax, i  
    add ax, t  
    mov x, ax  

    mov ax, l  
    add ax, u  
    mov y, ax  

    add ax, x  
    mov z, ax  

    mov si,2 
    mov nstr[si], '$'
    dec si 
    mov ax, z
    mov dx, 0

loop1:
    div idv

    add dl, '0'
    mov nstr[si],dl
    dec si
    mov dx,0

    cmp ax,0
    jne loop1

listn:
    mov ah, 09h
    mov dx, offset nstr
    int 21h 

stopprg:
    mov ah, 4ch
    int 21h
end
Michael
  • 57,169
  • 9
  • 80
  • 125
Nitescu Lucian
  • 255
  • 4
  • 18
  • 2
    The loop converts the value in `ax` into a string, so that it can be printed. As an aside, whoever wrote this code should use better variable names. – Michael Feb 07 '20 at 19:13
  • And if you just want a simple tmp var, that's what registers are for, not static storage. – Peter Cordes Feb 07 '20 at 20:44
  • Write pseudocode for what you want to do, translate into assembler (keeping pseudocode as vomments, adding comments telling where each varianle is kept -- presumably in a register -- and what registers are used for). – vonbrand Feb 07 '20 at 21:24

0 Answers0