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

Each of the questions on the next two pages asks you to convert a high-level cod

ID: 3675031 • Letter: E

Question

Each of the questions on the next two pages asks you to convert a high-level code sequence to x86 assembly. Please note that each of these code sequences is part of a larger function-do not worry about any of the function call and stack frame details discussed during lectures 14, 16, and 17. (That material will be covered on HW 4.) Implement the following conditional statement. You may assume that "X". "Y", and "Z" refer to 16-bit variables stored in memory, which can be directly accessed using those names (for example, MOV AX, X would move the contents of variable "X" to the register AX). Your solution should not modify AX or BX. Implement the following loop. As in question 1, assume "X" is a 16-bit variable in memory that can be accessed by name. ( Any loop that executes the correct number of iterations is acceptable you do not necessarily have to change your loop counter in exactly the same way as the for loop, since i is not used in the body of the loop.)

Explanation / Answer

1.
   CMP AX, 40       // compare AX with 40
   jge updateZ       // jump to updateZ if AX is greater than or equal to 40
                   // Else, Z = X + Y
   MOV Z, X       // mov X value to Z
   ADD Z, Y       // Add Y value to Z
   CMP Z, 0       // compare Z with 0
   jg updateX       // jump to updateX if Z is greater than 0
                   // Else, X = BX / 4
   mov EAX, BX       // Move BX value to EAX
   idiv 4           // divide EAX with 4
   mov X, EAX       // Move quotient value from EAX to X
  
updateX:           // X = BX * 8
   imul X, BX, 8   // multiply BX with 8 and store result in X
  
updateZ:           // Z = X - Y
   MOV Z, X       // move X value to Z
   SUB Z, Y       // Subtract Y value from Z
  
2.

   MOV i, 0       // move 0 to i
LOOP:
   CMP i, X       // compare i value with x
   jge EXIT       // jump to exit if i greater than or equal to X
   ADD AX, X       // add AX with X and store result in AX
   SUB BX, X       // Sutract X from BX and store result in BX
   CMP AX, BX       // Compare AX with BX
   je EXIT           // Jump if AX is equal to BX
   jmp LOOP       // Jump to LOOP
EXIT:

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