computer organization
Which choices contain correct implementations of the following pseudocode? (Assume that all values are unsigned):
if( eax > ebx )
mov dl,5;
else
mov dl,6;
CS 215
Homework 7
a.
cmp eax,ebx
jbe L2
mov dl,5
jmp L2
L1: mov dl,6
L2:
b.
cmp eax,ebx
ja L1
mov dl,5
jmp L2
L1: mov dl,6
L2:
c.
cmp eax,ebx
ja L1
mov dl,6
jmp L2
L1: mov dl,5
L2:
The answer is C
Which selection is the correct implementation of the following pseudocode?
if( val1 > val2 || val2 > eax )
mov ebx,1;
else
mov ebx,2;
a.
mov val1,ebx
cmp ebx,val2
jle L1
cmp val2,eax
jle L1
mov ebx,1
jmp L2
L1: mov ebx,2
L2:
b.
mov val1,ebx
cmp val2,ebx ; error
jg L1
cmp val2,eax
jg L2 ; error
mov ebx,2
jmp L2
L1: mov ebx,1
L2:
c.
mov val1,ebx
cmp ebx,val2
jg L1
cmp val2,eax
jg L1
mov ebx,2
jmp L2
L1: mov ebx,1
L2:
d.
mov val1,ebx
cmp ebx,val2
jng L1 ; error
cmp val2,eax
jg L1
mov ebx,2
jmp L2
L1: mov ebx,1
L2:
; error: uses AND logic
answer: b
Which selection correctly implements the following pseudocode?
while( int2 >= int1 )
{
add ebx,2
if( ebx > int2)
mov ebx,0
else
mov ebx,int1
}
a.
top:
mov eax,int2
cmp eax,int1
jnge L3
add ebx,2
cmp ebx,int2
jg L2 ; error
mov ebx,int1
jmp L3 ; error
L1: mov ebx,0
L2: jmp top
L3:
b.
top:
mov eax,int1 ; error
cmp eax,int2 ; error
jl L3
add ebx,2
cmp ebx,int2
jg L1
mov ebx,int1
jmp L2
L1: mov ebx,0
L2: jmp top
L3:
c.
top:
mov eax,int2
cmp eax,int1
jl L3
add ebx,2
cmp ebx,int2
jg L1
mov ebx,int1
jmp L2
L1: mov ebx,0
L2: jmp top
L3:
d.
top:
mov eax,int2
cmp eax,int1
jl L3
add ebx,2
cmp ebx,int2
jg L1
mov ebx,0 ; error
jmp L2
L1: mov ebx,int1 ; error
L2: jmp top
L3