0. Estra points (20 points): Consider the following generic C comparison functio
ID: 3705991 • Letter: 0
Question
0. Estra points (20 points): Consider the following generic C comparison function and its assembly language representation. C code byte comp (byte a, byte b): /a in rdi, b in rsi Assembly code: cmpb setinst %rsi, %rdi %al - Your jobs (fill-in blank): now show how the condition flags will be set with the corresponding SET instruction and the given values of a and b A 5 points set CF ZF SF OF %al setg 47 B. 5 points set CF ZF SF OF %al setl 23 47 C. 5 points CF ZF SF OF %al set 23 23 sete D. 5 points CF ZF SF OF %al set setne 23 47Explanation / Answer
cmpb instruction subtracts 2nd operand from 1st and sets flags accordingly.
set_instr %al sets %al to 1 according to the result of flags set by cmpb instruction
ZF is set if arithmetic operation results in 0.
CF is set if there is any carry/borrow
SF is set if result was negative
OF is set if there is an overflow i.e. arithmetic result is not in the range of 8-bit or 16-bit
A
setg 47 23
Here, 47 >23 therefore CF = 0 ZF = 0 SF = 0 OF = 0 and %al =1
B
setl 23 47
setl sets %al to 1 if SF != OF after instruction execution
Here, 23<47 therefore sets SF = 1
All other flags will remain 0
%al will be set to 1 as SF != OF
CF = 0 ZF = 0 SF = 1 OF = 0 and %al =1
C)
sete 23 23
Here, 23 -23 = 0 therefore sets ZF to 1 and %al to 1
CF = 0 ZF = 1 SF = 0 OF = 0 and %al =1
D)
setne 23 47
setne sets %al to 1 if ZF = 0
In this instruction, only SF flag will be set. ZF will remain 0 as ZF is set only if arithmetic result of subtraction is 0.
CF = 0 ZF = 0 SF = 1 OF = 0 and %al =1
set a b CF ZF SF OF %al 0 0 0 0 0Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.