ARITHMETIC AND LOGIC INSTRUCTIONS CH 5 QUESTIONS ANS

ARITHMETIC AND LOGIC INSTRUCTIONS CH 5 QUESTIONS ANS

MICROPROCESSOR SYSTEM ARITHMETIC AND LOGIC INSTRUCTIONS CHAPTER 5 PROBLEMS & QUESTIONS with Ans (BARRY B. BREY)

Problems and Questions-CHAPTER 5
1. Select an ADD instruction that will:
(a) add BX to AX – ADD AX, BX
(b) add 12H to AL – ADD AL, 12H
(c) add EDI and EBP – ADD EBP, EDI
(d) add 22H to CX – ADD CX, 22H
(e) add the data addressed by SI to AL – ADD AL,[SI]
(f) add CX to the data stored at memory location FROG- ADD FROG,CX
(g) add 234H to RCX- ADD RCX,234H

2. What is wrong with the ADD RCX,AX instruction?
Answer: You cannot use mixed-size registers.

3. Is it possible to add CX to DS with the ADD instruction?
Answer: No instruction is available to add to a segment register.

4. If AX = 1001H and DX = 20FFH, list the sum and the contents of each flag register bit (C, A, S, Z, and O)
after the ADD AX,DX instruction executes.
Answer: AX = 3100H, C = 0, A = 1, S = 0, Z = 0, and O = 0.

5. Develop a short sequence of instructions that adds AL, BL, CL, DL, and AH. Save the sum in the DH
register.
Answer: ADD AH, AL
 ADD AH, BL
 ADD AH, CL
 ADD AH, DL
 MOV DH, AH

6. Develop a short sequence of instructions that adds AX, BX, CX, DX, and SP. Save the sum in the DI
register.
Answer: ADD AX, BX
 ADD AX, CX
 ADD AX, DX
 ADD AX, SP

7. Develop a short sequence of instructions that adds ECX, EDX, and ESI. Save the sum in the EDI register.
Answer: MOV EDI, ECX
 ADD EDI, EDX
 ADD EDI, ESI

8. Develop a short sequence of instructions that adds RCX, RDX, and RSI. Save the sum in the R12 register.
Answer : MOV DI,AX
 MOV R12,RCX
 ADD R12,RDX
 ADD R12,RSI

9. Select an instruction that adds BX to DX, and also adds the contents of the carry flag (C) to the result.
Answer: ADC DX,BX

10. Choose an instruction that adds 1 to the contents of the SP register.
Answer: INC SP


11. What is wrong with the INC [BX] instruction?
Answer: The instruction codes does not specify the size of the data addressed by BX and can be
corrected with a BYTE PTR, WORD PTR, DWORD PTR, or QWORD PTR.
12. Select a SUB instruction that will:
(a) subtract BX from CX - SUB CX,BX
(b) subtract 0EEH from DH - SUB DH,0EEH
(c) subtract DI from SI - SUB SI,DI
(d) subtract 3322H from EBP - SUB EBP,3322H
(e) subtract the data address by SI from CH - SUB CH,[SI]
(f) subtract the data stored 10 words after the location addressed by SI from DX - SUBDX,[SI+10]
(g) subtract AL from memory location FROG- SUB FROG,AL
(h) subtract R9 from R10- SUB R10,R9

13. If DL = 0F3H and BH = 72H , list the difference after BH is subtracted from DL and show the contents
of the flag register bits.
Answer: DL = 81H, S = 1, Z = 0, C = 0, A = 0, P = 0, O = 1

14. Write a short sequence of instructions that subtracts the numbers in DI, SI, and BP from the AX
register. Store the difference in register BX.
Answer: MOV BX,AX
 SUB BX,DI
 SUB BX,SI
 SUB BX,BP

15. Choose an instruction that subtracts 1 from register EBX.
Answer: DEC EBX

16. Explain what the SBB [DI–4],DX instruction accomplishes.
Answer: The contents of DX and the carry flag are subtracted from the 16-bit contents of the data segment memory addressed by DI – 4 and the result is placed into DX.

17. Explain the difference between the SUB and CMP instruction.
Answer: Both instructions subtract, but compare does not return the difference, it only changes the flag bits to reflect the difference.

18. When two 8-bit numbers are multiplied, where is the product found?
Answer: AH (most significant) and AL (least significant)

19. When two 16-bit numbers are multiplied, what two registers hold the product? Show the registers
that contain the most and least significant portions of the product.
Answer: AH contains the most significant part of the result and AL contains the least significant part of the result.

20. When two numbers multiply, what happens to the O and C flag bits?
Answer: The O and C flags contain the state of the most significant portion of the product. If the most significant part of the product is zero, then C and O are zero.

21. Where is the product stored for the MUL EDI instruction?
Answer: EDX and EAX as a 64-bit product
22. Write a sequence of instructions that cube the 8-bit number found in DL. Load DL with a 5 initially,
and make sure that your result is a l6-bit number.
Answer: MOV DL,5
 MOV AL,DL
 MUL DL
 MUL DL

23. What is the difference between the IMUL and MUL instructions?
Answer: IMUL is signed multiplication while MUL is unsigned.

24. Describe the operation of the IMUL BX,DX,100H instruction.
Answer : BX = DX times 100H
 900 APPENDIX D

25. When 8-bit numbers are divided, in which register is the dividend found?
Answer: AX

26. When l6-bit numbers are divided, in which register is the quotient found?
Answer: AX

27. When 64-bit numbers are divided, in which register is the quotient found?
Answer: RAX

28. What errors are detected during a division?
Answer: The errors detected during a division are a divide overflow and a divide by zero.

29. Explain the difference between the IDIV and DIV instructions.
Answer: IDIV is seined division, while DIV is unsigned division.

30. Where is the remainder found after an 8-bit division?
Answer: AH

31. Where is the quotient found after a 64-bit division?
Answer: RAX

32. Write a short sequence of instructions that divides the number in BL by the number in CL and then multiplies the result by 2. The final answer must be a 16-bit number stored in the DX register.
Answer : MOV AH,0
 MOV AL,BL
 DIV CL
 ADD AL,AL
 MOV DL,AL
 MOV DH,0
 ADC DH,0

33. Which instructions are used with BCD arithmetic operations?
Answer: DAA and DAS
34. Explain how the AAM instruction converts from binary to BCD.
Answer: It divides by AL by 10. This causes numbers between 0 and 99 decimal to be converted to unpacked BCD in AH (quotient) and AL (remainder).

35. Which instructions are used with ASCII arithmetic operations?
Answer: AAA, AAS, AAD, and AAM

36. Develop a sequence of instructions that converts the unsigned number in AX (values of 0–65535) into a 5-digit BCD number stored in memory, beginning at the location addressed by the BX register in the data segment. Note that the most significant character is stored first and no attempt is made to blank
leading zeros.
Answer:
PUSH DX
PUSH CX
MOV CX,1000
DIV CX
MOV [BX],AL
MOV AX,DX
POP CX
POP DX
PUSH AX
AAM
MOV [BX+1],AH
MOV [BX+2],AL
POP AX
MOV AL,AH
AAM
MOV [BX+3],AH
MOV [BX+4],AL

37. Develop a sequence of instructions that adds the 8-digit BCD number in AX and BX to the 8-digit BCD number in CX and DX. (AX and CX are the most significant registers. The result must be found in CX and DX after the addition.)
Answer:
 PUSH AX
 MOV AL, BL
 ADD AL, DL
 DAA
 MOV AL, BH
 ADC AL, DH
 DAA
 MOV BX, AX
 POP AX
 ADC AL, CL
 DAA

38. Does the AAM instruction function in the 64-bit mode?
Answer: Neither the BCD or the ASCII instructions function in the 64-bit mode.
39. Select an AND instruction that will:
(a) AND BX with DX and save the result in BX – AND BX,DX
(b) AND 0EAH with DH – AND DH,0EAH
(c) AND DI with BP and save the result in DI – AND DI,BP
(d) AND 1122H with EAX – AND EAX,112H
(e) AND the data addressed by BP with CX and save the result in memory – AND [BP],CX
(f) AND the data stored in four words before the location addressed by SI with DX and save the result in DX- AND DX, [SI-8]
(g) AND AL with memory location WHAT and save the result at location WHAT – AND WHAT,AL

40. Develop a short sequence of instructions that clears (0) the three leftmost bits of DH without changing the remainder of DH and stores the result in BH.
Answer: MOV BH,DH
 AND BH,1FH

41. Select an OR instruction that will:
(a) OR BL with AH and save the result in AH – OR AH,BL
(b) OR 88H with ECX – OR ECX,88H
(c) OR DX with SI and save the result in SI – OR SI,DX
(d) OR 1122H with BP – OR BP,1122H
(e) OR the data addressed by RBX with RCX and save the result in memory- OR [RBX],RCX (f ) OR the data stored 40 bytes after the location addressed by BP with AL and save the result in AL - OR AL, [BP+40]
(g) OR AH with memory location WHEN and save the result in WHEN – OR WHEN,AH

42. Develop a short sequence of instructions that sets (1) the rightmost 5 bits of DI without changing the remaining bits of DI. Save the results in SI.
Answer: MOV SI,DI
 OR SI,1FH

43. Select the XOR instruction that will:
(a) XOR BH with AH and save the result in AH – XOR AH,BH
(b) XOR 99H with CL – XOR CL,99H
(c) XOR DX with DI and save the result in DX – XOR DX,DI
(d) XOR lA23H with RSP- XOR RSP,1A23H
(e) XOR the data addressed by EBX with DX and save the result in memory – XOR [EBX],DX (f) XOR the data stored 30 words after the location addressed by BP with DI and save the result in DI
Answer: XOR DI, [BP+60] (g) XOR DI with memory location WELL and save the result in DI – XOR
DI,WELL
44. Develop a sequence of instructions that sets (1) the rightmost 4 bits of AX; clears (0) the leftmost 3 bits of AX; and inverts bits 7, 8, and 9 of AX.
Answer:OR AX,0FH
 AND AX,1FFFH
 XOR AX,0380H

45. Describe the difference between the AND and TEST instructions.
Answer: The only difference is that the logical product is lost after TEST.

46. Select an instruction that tests bit position 2 of register CH.
Answer: TEST CH,4

47. What is the difference between the NOT and the NEG instruction?
Answer: NOT is one’s complement and NEG is two’s complement.

48. Select the correct instruction to perform each of the following tasks:
(a) shift DI right three places, with zeros moved into the leftmost bit
Answer: SHR DI,3
(b) move all bits in AL left one place, making sure that a 0 moves into the rightmost bit Position
Answer: SHL AL,1
(c) rotate all the bits of AL left three places Answer: ROL AL,3
(d) rotate carry right one place through EDX Answer: RCR EDX,1
(e) move the DH register right one place, making sure that the sign of the result is the same as the sign of the original number Answer: SAR DH,1

49. What does the SCASB instruction accomplish?
Answer: AL is compared with the byte contents of the extra segment memory location addressed by DI.

50. For string instructions, DI always addresses data in the ____________ segment.
Answer: Extra

51. What is the purpose of the D flag bit?
Answer: The D flag selects whether SI/DI are incremented (D=0) or decremented (D=1).

52. Explain what the REPE prefix does when coupled with the SCASB instruction.
Answer: The SCASB instruction is repeated while the condition is equal as long as CX is not zero.

53. What condition or conditions will terminate the repeated string instruction REPNE SCASB?
Answer: An equal condition or if CX decrements to 0.

54. Describe what the CMPSB instruction accomplishes.
Answer: CMPSB compares the byte contents of the byte in the data segment addressed by SI with the byte in the extra segment addressed by DI.

55. Develop a sequence of instructions that scans through a 300H-byte section of memory called LIST, located in the data segment, searching for a 66H.
Answer: MOV DI, OFFSET LIST
 MOV CX, 300H
 CLD
 MOV AL, 66H
 REPNE SCASB
56. What happens if AH = 02H and DL = 43H when the INT 21H instruction is executed?
Answer: In DOS the letter C is displayed.

Chapter 5 Arithmetic and Logic Instructions, Solution to the Problems and Questions, Arithmetic instructions in 8085 microprocessor PROBLEMS solution, BARRY B. BREY Chapter 5 solution, THE INTEL MICROPROCESSORS CHAPTER 5 solution, MICROPROCESSOR SYSTEM ARITHMETIC AND LOGIC INSTRUCTIONS CHAPTER 5 PROBLEMS, LOGIC INSTRUCTIONS PROBLEMS & QUESTIONS, ARITHMETIC INSTRUCTIONS PROBLEMS & QUESTIONS, CHAPTER 5 ARITHMETIC AND LOGIC INSTRUCTIONS ans