pg 152-153
6.2.1
A DW 1111h
B DW 2222h
push A
mov ax,3333h
push ax
push B
pop ax ;ax = 2222h
pop B ;B = 3333h
mov bx,4444h
push bx
pop ax ;ax = 4444h
pop bx ;bx = 1111h
6.2.2
What is the effect of:
push ax
push bx
pop ax
pop bx
Pop takes out the last item added (or the newest item in the stack) so here, pop ax takes out the
value of bx and puts it in ax, then pop bx takes the vaue of ax and puts it in bx
6.2.3
You can't save and restore sp using
push sp
pop sp
because when you push the value of sp, and then pop you want to pop it back into sp, it is already in sp
pg 109-110 (some done in previous HW)
4.
Eliminate jumps:
cmp A,14 cmp A,14
jge S1 jnge S2
jmp S2 mov X,21
S1: S2:
mov X,21
S2:
cmp X,ax cmp X,ax
jne L1 je L2
jmp L2 neg X
L1: inc X
neg X L2:
inc X
L2:
cmp ax,0 cmp ax,0
jg around jng over
jmp over inc ax
around: jmp through
inc ax over: dec,ax
jmp through through:
over:
dec ax
through: