Oria Gruber
Oria Gruber

Reputation: 1533

Assembly 8086 homework - fill in the blank, misunderstanding

Firstly I'd like to apologize, english is not my native tongue and I couldn't come up with a title that better fits my situation.

I was given this incomplete assembly code:

.code
    mov [mybyte],______
    mov SP,0574h
    xor ax,ax
here:
    add AL,[mybyte]
    push AX
    dec BYTE PTR [mybyte]
    jnz here
    pop es
    nop

The question is: What should be written where _____ is, such that when we reach the "nop" command, the value of SP will be 570.

I understand the question, and I think I understand the code as well, but the problem is, the way i see it- SP never changes. The only place in the code where SP is referred to is at the line mov sp,0574h. So no matter what we write where ____ is, SP will not change.

Am I correct? Or did I misunderstand the code?

Upvotes: 1

Views: 282

Answers (2)

Welcor
Welcor

Reputation: 3073

Sry. Cant use comment yet. To answer your second question: ES 0006 is correct. mybyte is decreased from 3 to 0 is right as well. The only thing you are wrong with at the moment, is what values are pushed to the stack. Just check again what happens to AL every loop cycle.

Spoiler:

Do not read if you want to find out yourself:

Mybyte is not moved into AL but added to it: 0 + 3 + 2 + 1 = 6

Upvotes: 0

Jester
Jester

Reputation: 58762

push changes SP, namely it decrements by 2. pop also changes it, it does the opposite, it adds 2. This is assuming 16 bit mode.

Since the final pop adds a 2 back, you need to loop 3 times to get 570h from 574h. Thus the correct value is 3.

push AX ; SP = 572h
...
push AX ; SP = 570h
...
push AX ; SP = 56Eh
...
pop es  ; SP = 570h

Upvotes: 5

Related Questions