You are on page 1of 4

Discussion CH6

In the following instruction sequence. Show the changed


value of AL where indicated. In binary: (6.2.9.1)
mov a1,00001111b
and al,00111 011b a. al = 00001011b
mov al,6Dh
and al,4Ah b . al=48h
mov al,0000111 lb
or al,61h c . al=6Fh
mov al,94h
xor al,37h d. al=0A3h

In the following instruction sequence, show the changed


value of AL where indicated, in hexadecimal :(6.2.9.2)
mov a1 ,7Ah
not a1 a. al=85h
mov a1,3Dh
and al ,74h b. al=34h
mov al, 9Bh
or al,35h c. al=0BFh
mov al,72h
xor al ,0DCh d. al=0AEh

In the following instruction sequence, show the values of the


Carry, Zero, and Sign flags where indicated (6.2.9.3)
mov al,00001111b
test al ,2 a . CF=0 ZF=0 SF=0
mov al ,6
cmp al ,5 b . CF=0 ZF=0 SF=0
mov al ,5
cmp al ,7 c . CF=1 ZF=0 SF =1
Write a single instruction that clears the high 8 bits of AX and
does not change the low 8 bits.(6.2.9.4)
and ah,0h

Write a single instruction that reverses all the bits in EAX


(do not use the NOT instruction).(6.2.9.6)
xor eax,0FFFFFFFFh

Write instructions that set the Zero flag if the 32-bit value in
EAX is even, and clear the Zero flag if EAX is odd.(6.2.9.11)
test eax,1h

Write instructions that calculate the parity of the 32-bit


memory operand.(6.2.9.12)
mov ax,0
xor al,ah
xor al, byte ptr [x+3]
xor al, byte ptr [x+2]
xor al, byte ptr [x+1]
xor al, byte ptr [x]

(Yes/No): Are the JB and JL instructions equivalent? (6.3.6.5)


No (JB uses unsigned operands, whereas JL uses signed operands.)

(Yes/No): Will the following code jump to the label named


Target?(6.3.6.8)
mov ax,8109h
cmp ax,26h
jg Target
No, because the jg is used with signed value and the value in ax is
negative -265
(Yes/No): Will the following code jump to the label named
Target? (6.3.6.10)
mov ax,-42
cmp ax,26
ja Target
yes, because ja used for signed values and the value in ax will be 802Ah

Write instructions that clear bits 0 and 1 in AL. If the


destination operand is equal to zero. jump to label L3.
Otherwise, jump to label L4? (6.3.6.13)
and al,11111100b
jz L3
jmp L4

Implement the following pseudocode in assembly language


(6.5.5.5)
if( bx > ex AND bx > dx) OR ( dx > ax )
X = 1;
else
X = 2;

cmp bx,cx ; bx > cx?


jna L1 ; no: try condition after OR
cmp bx,dx ; yes: is bx > dx?
jna L1 ; no: try condition after OR
jmp L2 ; yes: set X to 1

;-----------------OR(dx > ax) -------------------

L1: cmp dx,ax ; dx > ax?


jna L3 ; no: set X to 2
L2: mov X,1 ; yes:set X to 1
jmp next ; and quit
L3: mov X,2 ; set X to 2
next:
Rewrite the following code (from Section 6.5.3.1 so that it is
functionally equivalent, but uses fewer instructions(6.5.5.6):
mov eax,op1
mov ebx,op2
mov ecx,op3
L1: cmp eax,ebx
jl L2
jmp L7
L2: inc eax
L3: cmp ebx,ecx
Je L4
jmp L5
L4: mov X,2
jmp L6
L5: mov X,3
L6: jmp L1
L7: mov op1,eax

Solution:

mov eax,op1
mov ebx,op2
mov ecx,op3
L1: cmp eax,ebx
jge L7
inc eax
L3: cmp ebx,ecx
jne L5
mov X,2
jmp L6
L5: mov X,3
L6: jmp L1
L7: mov op1,eax

You might also like