In: Computer Science
Each of these problems gives "before" conditions and instruction. Give the indicated "after" state. Data should appear as hexadecimal values. All instructions are valid.
Before instruction executed after
1) ECX: 0A 00 BF 7A mov ECX, -127 ECX:
2) ECX: FF FF FF C8 add ch, 2 ECX:
ZF: SF: CF: OF:
3) EAX: 12 34 56 78 xchg ah, al EAX:
4) EDX: DD FF 00 01 neg dl EDX:
ZF: SF:
5) EAX: 01 00 05 45 sub ah, 11b EAX:
ZF: SF: CF: OF:
6) EAX: 00 0F 00 01 mul bx EAX:
EBX: 11 FF 00 0A EDX:
EDX:37 01 00 00
7) EAX: 00 00 00 1A div ECX EDX:
EAX:00 00 00 01
ECX: 00 00 00 0E
EDX:00 00 00 0C
8) ECX: 0A 00 BF 7A movsx ECX, ch ECX:
9) EAX: 0A FF BF 7A movzx ax, al EAX:
(1) Instruction mov ECX, -127 and Before ECX = 0A 00 BF 7A
Answer: ECX = FF FF FF 81 (hexadecimal)
Description:
• mov ECX, -127 ; move decimal value -127 to ECX register.
• Signed decimal value will be stored in 2's complement form.
• So, -12710 = 111111111111111111111111100000012 = FF FF FF 8116 in 2's complement form.
• Register ECX = FF FF FF 81.
(2) Instruction: add ch, 2 and Befor ECX = FF FF FF C8
Answer: ECX: FF FF 01 C8 (hexadecimal) and ZF: SF: CF: OF = 0 : 1 : 1: 0
Description:
• add ch, 2 ; Addition. Register CH = CH + 2.
• Register CH in ECX register is from bit 8 to 15.
• Here, CH = FF. Performing the addition CH = CH + 2 = FF + 2 = 01 with carry = 1.
• Register ECX = FF FF 01 C8.
• It will set the carry flag and the sign flag.
• Carry Flag = 1 and Sign Flag = 1
(3) Instruction xchg ah, al and Before EAX: 12 34 56 78
Answer: EAX = 12 34 78 56
Description:
• xchg ah, al ; Exchange the content of the registers. Put AH in AL and AL in AH register.
• Before register AH = 56 and AL = 78. After executing the exchange instruction, AH = 78 and AL = 56. So, register EAX = 12 34 78 56.
(4) Instruction neg dl and Before EDX: DD FF 00 01
Answer: EDX = DD FF 00 FF and ZF : SF = 0 : 1
Description:
• neg dl ; Two's Complement Negation.
• This instruction multiplies the operand by -1. That means it makes the positive value to negative and negative value to positive value.
• Here, DL = 01. After the instruction, DL = FF (2's complement form of -1) and Sign flag = 1.
• EDX = DD FF 00 FF
(5) Instruction sub ah, 11b and Before EAX: 01 00 05 45
Answer: EAX = 01 00 02 45 and ZF: SF: CF: OF = 0 : 0 : 0 : 0
Description:
• sub ah, 11b ; Subtract. AH = AH - 11(binary)
• Before AH = 05. Performing the subtraction AH = 05 = 0000 0101 - 0000 0011 = 0000 0011.
• EAX = 01 00 02 45
• Flags will be not affected by provided instruction.
(6) Instruction mul bx and Before EBX: 11 FF 00 0A, EAX: 00 0F 00 01, EDX:37 01 00 00
Answer: EAX = 00 0F 00 0A
Description:
• mul bx ; Multiplication. Multiply BX with AX register. AX * BX = DX : AX.
• Here, AX = 00 01 and BX = 00 0A. Performing the multiplication AX * BX = 00 01 * 00 0A = 00 0A.
• So, the Register AX = 00 0A
• Register EAX = 00 0F 00 0A.
(7) Instruction div ECX and Before EAX: 00 00 00 1A, ECX: 00 00 00 0E, EDX : 00 00 00 0C
Answer: EDX = 00 00 00 0C and EAX = 00 00 00 01
Description:
• div ECX; Division. Divide the ECX from the EAX register.
• EDX: EAX / ECX = Quotient in EAX and Remainder in EDX.
• Dividing 00 00 00 1A / 00 00 00 0E = EAX: 00 00 00 01 and EDX: 00 00 00 0C.
• So, EAX = 00 00 00 01.
(8) Instruction movsx ECX, ch and Before ECX: 0A 00 BF 7A
Answer: ECX = FF FF BF 7A
Description:
• movsx ECX, ch; Move with sign extension. Destination = sign-extended (source)
• Moves the source operand to destination operand with extending sign bit from 16 to 32 bit.
• Here, CH = BF. Move the value of CH to ECX and copy the sign bit = 1 from 16 to 32 bit.
• Register ECX = 1111 1111 1111 1111 1011 1111 0111 1010 = FF FF BF 7A.
(9) Instruction movzx ax, al and Before EAX: 0A FF BF 7A
Answer: EAX = 0A FF 00 7A
Description:
• movzx ax, al ; Move with zero extension. Destination = zero-extended (source)
• Moves the source operand to destination operand with extending zero from 15 to 8 bit.
• Here, AL = 7A. Move the value of AL to AX and copy the zero from 15 to 8 bit.
• Register EAX =0000 1010 1111 1111 0000 0000 0111 1010 = 0A FF 00 7A