\"I Sprint 12:39 PM a) what tbe ddereact between eenditional ond unconditioual j
ID: 2249433 • Letter: #
Question
"I Sprint 12:39 PM a) what tbe ddereact between eenditional ond unconditioual jumps. Why are japs apenive in pipelined architectures? b) What is the fusction of flags in latel archinectures? Explain it with the belp of an ecangle e) Cosvert the following C code into IA-32 assembly pregam You cn une the gote venion lo this or cnn choose to dinectly coswert it isto webly. However, te logle of the aebly prog should be eousistent and should glee accurate . int dunay-progran for.nidtern2 Cist at result-s; resultz D:Explanation / Answer
Answer:-a) In conditional jump, a condition is checked first if condition is TRUE then only jump instruction is executed, whereas in unconditional jump no condition is checked, jumping is sure in unconditional jumps. In conditional jump condition flags are being used like ZF, CF, AF, OF etc. On the basis of these flag status jump is decided. Example for conditional jump is like JZ, JNZ, JG, JE etc. Example for unconditional jump is like JMP.
In pipelined architecture jump instructions breaks the sequence of pipelinig. When jump instruction is to be executed, PC value is updated with the address in jump instruction but as we know in pipeling PC aleady keeps the address of next instruction to be executed. So the sequence of pipelinig breaks due to jump instructions.
b) Flags in a processor tells us about the ALU result. In INTEL the flags we have like zero flag(ZF), carry-flag(CF), over-flow flag(OF) etc, these flags are set or clearedas per the result in ALU. For example- if a SUB instruction produces result as zero then ZF is set, or if the addition ADD instruction produces any carry then CF flag is set. Suppose eax has value 0xA1 and ebx has same value then, SUB eax, ebx will give result as eax = 0xA1 -0xA1 = 0 and ZF =1.
c) The equivalent code in assembly can be written as-(assuming parameter passed is in eax)
dummy_program_for_midterm2: ;name of sub-routine
MOV ECX, EAX ;ecx = parameter value that is passed
MOV EAX, 1 ;now eax is like variable result in C
Compare1: ;label name Compare1
MOV EDX, 1 ;edx = 1 for comparision
CMP ECX, EDX ;compare ecx and edx
JG Loop1 ;goto Loop1
RET ; otherwise return from function
Loop1: ;label name Loop1
MOV EAX, [result] ;move value in result to eax
MOV EBX, ECX ;move value in ecx to ebx
MUL EBX ; do result = result*x as in C
.....
JMP Compare1
Note :- return value is in eax. The ... in the function because the picture is not showing clearly what is being done inside function. So please comment regarding that. Thanks.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.