Arithmetic and Logic Instructions: ADD Instruction Overview

Slide Note
Embed
Share

The ADD instruction is part of the Arithmetic and Logic Instructions First Group and is used to add a number from a source to a destination and store the result in the specified destination. The instruction affects flags like AF, CF, OF, SF, and ZF. It can operate with immediate numbers, registers, and memory locations. The source and destination must be of the same type, and certain considerations need to be taken into account when working with different types. Examples and exercises on using the ADD instruction are provided.


Uploaded on Dec 06, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Arithmetic and Logic Instructions First Group (ADD,SUB)

  2. First Group Instruction ADD, SUB,CMP, AND, TEST, OR, XOR REG, memory memory, REG REG, REG memory, immediate REG, immediate These instructions affect these flags only: CF, ZF, SF, OF, PF, AF.

  3. ADD instruction This instruction add a number from some source to a number in some destination and put the result in the specified destination. ADD Destination, Source D= D+S The source may be an immediate number, a register, or a memory location. The destination may be a register or a memory location.

  4. ADD instruction Notes: The source and the destination in an instruction can not both be memory locations. The source and the destination must be of the same type (bytes or words). If you want to add a byte to a word, you must copy the byte to a word location and fill the upper byte of the word with 0 s before adding. Flags affected: AF, CF, OF, SF, ZF.

  5. ADD instruction MOV AL, 11H ADD AL, 74H Ret

  6. ADD instruction MOV BX, 1234H MOV DX, 1111H ADD DX, BX Ret

  7. ADD instruction ADD AL, 74H ; Add immediate number 74H to content of AL. Result in AL ADD DX, BX ; Add content of BX to content of DX MOV [SI],5555H MOV DX,1111H ADD DX, [SI] ; Add word from memory at offset [SI] in DS to content of DX

  8. ADD instruction MOV AX,77H MOV BX,9032H ADD BX,AX RET

  9. ADD instruction EX1: Write an assembly language program to add the content of memory location A300 with the contain of memory location 2500 and store the result in memory location 3000?

  10. ADD instruction EX2: Write an assembly language program to copy 25h at the memory location A300 and 11h at the memory location 2500 add these two location and store the result in memory location 3000?

  11. ADD instruction EX3: Write an assembly language program to add 11111100B to 00010001b and store the result in CL register?

  12. ADD instruction EX4: Write an assembly language program to add 3571D to 00010001b and store the result in SP register?

  13. SUB instruction This instruction add a number from some source to a number in some destination and put the result in the specified destination. SUB Destination, Source D = D-S The source may be an immediate number, a register, or a memory location. The destination may be a register or a memory location.

  14. SUB instruction Notes: The source and the destination in an instruction cannot both be memory locations. The source and the destination must be of the same type (bytes or words). If you want to subtract a byte from a word, you must first move the byte to a word location such as a 16-bit register and fill the upper byte of the word with 0 s. Flags affected: AF, CF, OF, PF, SF, ZF.

  15. SUB instruction MOV CX, 1111H MOV BX, 00010001B SUB CX, BX ret

  16. SUB instruction MOV AX, 0FFFFH SUB AX, 3427H ret

  17. SUB instruction EX1: Write an assembly language program to subtract the content of memory location A300 with the contain of memory location 2500 and store the result in memory location 3000?

  18. SUB instruction EX2: Write an assembly language program to copy 25h at the memory location A300 and 11h at the memory location 2500, subtract these contains of the two location and store the result in memory location 3000?

  19. 8086 Microprocessor Execution Unit (EU) Architecture Auxiliary Carry Flag Carry Flag Flag Register This is set, if there is a carry from the lowest nibble, i.e, bit three during addition, or borrow for the lowest nibble, i.e, bit subtraction. This flag is set, when there is a carry out of MSB in case of addition or a borrow in case of subtraction. three, during Zero Flag Parity Flag Sign Flag This flag is set, if the result of the computation or comparison performed by an instruction is zero This flag is set to 1, if the lower byte of the result contains even number of 1 s ; for odd number of 1 s set to zero. This flag is set, when the result of any computation is negative 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 OF DF IF TF SF ZF AF PF CF Tarp Flag Over flow Flag If this flag is set, the processor enters the single step execution mode by generating internal interrupts after the execution of each instruction This flag is set, if an overflow occurs, i.e, if the result of a signed operation is large enough to accommodate in a destination register. The result is of more than 7-bits in size in case of 8-bit signed operation and more than 15-bits in size in case of 16-bit sign operations, then the overflow will be set. Direction Flag Interrupt Flag This is used by string manipulation instructions. If this flag bit is 0 , the string is processed beginning from the lowest address to the highest address, i.e., auto incrementing mode. Otherwise, the string is processed from the highest address towards the lowest address, i.e., auto incrementing mode. Causes the 8086 to recognize external mask interrupts; clearing IF disables these interrupts. 19

  20. Register Flag See Carry Flag MOV AL,0FFH ADD AL,01 RET *** MOV AX,0FFFFH ADD AX,01 RET

  21. Register Flag MOV Al, 01h ; 13h MOV Ah, 01h ; 45h SUB AH,AL Ret ZF (Zero Flag): if the result of ADD or SUB is 0 ZF =1 else ZF=0

  22. Register Flag MOV Al, 11h MOV Ah, 01h SUB AH,AL ret SF (Sign Flag): if the result of ADD or SUB is (-) SF =1 else SF=0 MOV Al, 11h mov Ah, 01h SUB AL,AH ret

  23. Register Flag EX: Let AL= F3 and AH= F5 MOV Al, 11110011B mov Ah, 11110101B ADD AL,AH ret CF (Carry Flag): if the result of ADD or SUB contains carry the CF =1 else CF=0

  24. EX: Y= 3010 +15 10 compute the value of y and put it in BX register

More Related Content