Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Translate the following Python program into the machine language described in Ap

ID: 3855076 • Letter: T

Question

Translate the following Python program into the machine language described in Appendix C. You may assume that the program begins at address 00, and the x is stored at memory cell whose address is XY.
x= 0

while (x < 3):

      x=x+ 1

part B

Translate the high-level statement
if (X == 0): Z=Y+ W
else: Z=Y+ X
into the machine language of Appendix C, assuming that W, X, Y, and Z are all values represented in two’s complement notation, each using one byte of memory

part C

Simplify the following code segment

Y= 5

if (Y == 7 ):

Z= 8

else:

Z= 9

Explanation / Answer

1.

Given -

x= 0

while (x < 3):

x=x+ 1

Assembly/Machine Code:

Assumption is x stored in edx register.

movl $0, %ecx

loop: cmpl $3, %edx

jge endloop

addl $1,%edx

jmp loop

endloop:

2.

Given -

if (X == 0): Z=Y+ W

else: Z=Y+ X

Assembly/Machine Code:

Assumption is x stored in edx register.

y stored in eax register

z stored in ebx register

w stored in t1 register

movl $0, %ecx

cmpl $0, %edx

jne elseBlock

addl %eax, %t1

movl %t1, %ebx

jmp endloop

elseBlock: addl %eax,%edx

movl %edx,%ebx

endloop:

3.

Simplify -

Y= 5

if (Y == 7 ):

Z= 8

else:

Z= 9

Since Y = 5 is present before the "if" loop, the "then" part of "if" loop is useless as it is

treated as DEAD CODE, we can remove that and the refined code is as below.

Y = 5

Z = 9

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote