Docsity

Assembly Language Instructions and Examples: A Comprehensive Guide, Thesis of Engineering

Partial preview of the text

Download Assembly Language Instructions and Examples: A Comprehensive Guide and more Thesis Engineering in PDF only on Docsity!

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ¾^ AAA^ Instruction - ASCII Adjust after Addition ¾^ AAD^ Instruction - ASCII adjust before Division ¾^ AAM^ Instruction - ASCII adjust after Multiplication ¾^ AAS^ Instruction -

ASCII Adjust for Subtraction ¾^ ADC^ Instruction - Add with carry. ¾^ ADD^ Instruction - ADD destination, source ¾^ AND^ Instruction - AND corresponding bits of two operands

Instruction Description

M. Krishna Kumar^

MAM/M2/LU5/V1/^

Example

¾^ AAA^ Instruction

-^ AAA converts the result of the addition of two valid unpacked BCD digits to a valid 2-digitBCD number and takes the AL register as its implicit operand.

Two operands of the addition must have its lower 4 bits contain a number in the range from 0-9.The AAAinstruction then adjust AL so that it contains a correct BCDdigit. If the addition produce carry (AF=1), the AH register isincremented and the carry CF and auxiliary carry AF flags areset to 1. If the addition did not produce a decimal carry, CF andAF are cleared to 0 and AH is not altered. In both cases thehigher 4 bits of AL are cleared to 0.

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ¾^ AAD^ Instruction

-^ ADD converts unpacked BCD digits in the AH and AL register into a single binary number inthe AX register in preparation for a division operation.Before executing AAD, place the Most significantBCD digit in the AH register and Last significant in the ALregister. When AAD is executed, the two BCD digits arecombined into a single binary number by settingAL=(AH*10)+AL and clearing AH to 0. ¾ Example:MOV^ AX,0205h

;The unpacked BCD number 25 AAD^

Example (cont..) ;After AAD , AH=0 and;AL=19h (25)

M. Krishna Kumar^

MAM/M2/LU5/V1/^ After the division AL will then contain the unpacked BCDquotient and AH will contain the unpacked BCD remainder. ¾ Example:

;AX=0607 unpacked BCD for 67 decimal;CH=09H AAD^

;Adjust to binary before division;AX=0043 = 43H =67 decimal DIV CH^

Example (cont..) ;Divide AX by unpacked BCD in CH;AL = quotient = 07 unpacked BCD;AH = remainder = 04 unpacked BCD

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ¾^ Example:MOV

AL, 5MOV BL, 7MUL BL^

;Multiply AL by BL , result in AX AAM^

Example (cont..) ;After AAM, AX =0305h (BCD 35)

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ¾^ AAS^ Instruction

-^ AAS converts the result of the subtraction of two valid unpacked BCD digits to a single validBCD number and takes the AL register as an implicit operand.The two operands of the subtraction must have its lower 4 bitcontain number in the range from 0 to 9 .The AAS instructionthen adjust AL so that it contain a correct BCD digit. MOV^ AX,0901H

;BCD 91

SUB^ AL, 9

;Minus 9 AAS^

Example (cont..) ; Give AX =0802 h (BCD 82)

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ( b )^ ; AL = 0011 0101 =ASCII

; BL = 0011 1001 = ASCII

SUB^ AL, BL

;( 5 - 9 ) Result :;AL = 1111 1100 = - 4; in 2’s complement CF = 1 AAS^

Example (cont..) ;Results :;AL = 0000 0100 =BCD 04;CF = 1 borrow needed.

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ¾^ ADD^ Instruction

-^ These instructions add a number from source to a number from some destination and put theresult in the specified destination. The add with carryinstruction ADC, also add the status of the carry flag into theresult. The source and destination must be of same type ,means they must be a byte location or a word location. If youwant to add a byte to a word, you must copy the byte to a wordlocation and fill the upper byte of the word with zeroes beforeadding. ¾ EXAMPLE:ADD^ AL,74H

Example (cont..)^ ;Add immediate number 74H to; content of AL

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ;^ Addition of Un Signed numbers ADD^ CL, BL ;CL = 01110011 =115 decimal

;+ BL = 01001111 = 79 decimal;Result in CL = 11000010 = 194 decimal;^ Addition of Signed numbers ADD^ CL, BL ;CL = 01110011 = + 115 decimal

;+ BL = 01001111 = +79 decimal;Result in CL = 11000010 = - 62 decimal ; Incorrect because result is too large to fit in 7 bits.

Example (cont..)

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ¾^ AND^ Instruction

-^ This Performs a bitwise Logical AND of two operands. The result of the operation is stored inthe op1 and used to set the flags.

AND^ op1, op To perform a bitwise AND of the two operands, each bitof the result is set to 1 if and only if the corresponding bit inboth of the operands is 1, otherwise the bit in the result I clearedto 0. AND^ BH, CL

;AND byte in CL with byte in BH;result in BH AND^ BX,00FFh

Example (cont..)^ ;AND word in BX with immediate;00FFH. Mask upper byte, leave;lower unchanged

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ¾^ CALL^ Instruction•^ Direct within-segment (near or

intrasegment)

-^ Indirect within-segment (near or intrasegment)•^ Direct to another segment (far or intersegment)•^ Indirect to another segment (far or intersegment) ¾^ CBW^ Instruction

-^

Convert signed Byte tosigned word ¾^ CLC^ Instruction

-^

Clear the carry flag ¾^ CLD^ Instruction

-^

Clear direction flag

Example (cont..)

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ¾^ CLI^ Instruction

-^

Clear interrupt flag ¾^ CMC^ Instruction

-^

Complement the carryflag ¾^ CMP^ Instruction

-^

Compare byte or word-CMP^ destination, source. ¾^ CMPS/CMPSB/CMPSW^ Instruction

-^

Compare string bytes orstring words ¾^ CWD^ Instruction

-^

Convert Signed Word to -Signed Double word

Example (cont..)

M. Krishna Kumar^

MAM/M2/LU5/V1/^

Example (cont..)

-^ A RET instruction at the end of the procedure will returnexecution to the instruction after the CALL by coping theoffset saved on the stack back to IP.A Far CALL is a call to aprocedure which is in a different from that which contains theCALL instruction. When 8086 executes the Far CALLinstruction it decrements the stack pointer by two again andcopies the content of CS register to the stack. It thendecrements the stack pointer by two again and copies theoffset contents offset of the instruction after the CALL to thestack. Finally it loads CS with segment base of the segmentwhich contains the procedure and IP with the offset of the firstinstruction of the procedure in segment. A RET instruction atend of procedure will return to the next instruction after theCALL by restoring the saved CS and IP from the stack.

M. Krishna Kumar^

MAM/M2/LU5/V1/^ ;Direct within-segment ( near or intrasegment )CALL^

MULTO^

;MULTO is the name of the procedure. The assembler determines displacement ofMULTO from the instruction after the CALL and codesthis displacement in as part of the instruction .;Indirect within-segment ( near or intrasegment )CALL^

BX^

; BX contains the offset of the first instruction of the procedure .Replaces contents ofword of IP with contents o register BX.

Example (cont..)