Showing posts with label Aritmetic-Logic. Show all posts
Showing posts with label Aritmetic-Logic. Show all posts

Wednesday, May 19, 2010

Shifting & Rotating

Question
Calculate the changes in AL by each of the instruction below. (AH=33h,CF=0 and each instruction is not related to each other)
i.    RCR AL,2
ii.    SHL AL, 2    
iii.    SAR AL,2    

Answer

i.    RCR AL,2
AH=01110111 CF=0
rotate with carry to the right two times
AH = 10011101 CF=1
Answer >> AH = 9D16 CF=1

ii.    SHL AL, 2    
AH=01110111 CF=0
shift to the left two times
AH = 11011100 CF=0
Answer >> AH= DC16 CF=0

iii.    SAR AL,2    
AH=01110111 CF=0
shift arithmetic to the right two times (if the sign bit is one, then number 1 will be shifted into the stream, if not zero will be inserted, in this case the sign bit is 0 so zero will be inserted)
AH= 00011101 CF=0
Answer >> AH= 1D16 CF=0

Monday, May 17, 2010

Basic arithmetic assembly programming

Question

Indicate any value/data/register that has been change by every program line below

MOV BX, 0202h
MUL BL
ADD BX, ((AX))
MOV DX,ES:[0001h]
MOV [BP],CX



Answer

MOV BX, #0202h // BX = 0202h

MUL BL // AX = 0001h x 02h = 00002h

ADD BX, ((AX)) // BX = 11ABh + (0004)=11ABh + 0001h=11ACh

MOV DX,ES:[0001h] // DX =8967h

MOV [BP],CX // 50005 = 1F, 50006=CB

Arithmetic & Logic assembly programming

Question

Identify the new value of AX, BX dan CX after the program below.

MOV AX, 1234H

MOV BX, ABCDH
MOV CH, 1D
MOV CL, 255D
OR AH, 10H
AND BX , 1111000011110000b
NOT CX

Answer
 
AH  = 12h = 00010010

          10h = 00010000

AH OR AL = 00010010
--> AX = 1234h

BX = ABCD --> A0C0

CX = NOT ( 0AFF) = 1111 0101 0000 0000b = F500h

Tuesday, May 11, 2010

Rotating & Shifting tutorial

Question
Calculate the changes in AX and CF for each of the instruction in the program below (Assume initial CF=0)

MOV AX, F0h
SHL AH,3
SAR AH,4
RCR AH,1
OR   AH,AL

Answer

MOV AX, F0h
--> AX = 0000 0000 | 1111 0000
--> CF = 0


SHL AH,3
--> AH = 0000 0000 , shift to left 3 times will equal to 0000 0000 (no changes)
--> AX = 0000 0000 | 1111 0000
--> CF = 0



SAR AH,4
--> AH = 0000 0000 , shift arithmetic to right 3 times will make AH equal to 0000 0000 (no changes)

--> AX = 0000 0000 | 1111 0000
--> CF = 0

RCR AH,1
--> AH = 0000 0000 , shift with carry to right 1 times will make AH equal to 0000 0000 (no changes) and CF equal to zero
--> AX = 0000 0000 | 1111 0000
--> CF = 0


OR AH,AL
--> AH = 0000 0000
--> AL =  1111 0000
--> OR AH,AL --> AH = AH OR AL = 1111 0000 (F0h) --> AX = F0F0h , CF = 0


ROL AL,3
--> AL=11110000, rotate to left 3 times will make AL equal to 1000 0111 (87h)
--> AX = F087h, CF=1

Adding 64 bits of data tutorial

Question
Show how to add the following two 64 bits of data using 8088/8086 assembly programming . The final answer must be located at CX-DX combination. Then show the final value of CF,PF,ZF,SF and AF flags.

X=4322FFFFh
Y=43210001h

Answer:

     CX DX
+   AX BX
------------
     CX DX
------------

DX+BX can be done using the normal ADD DX,BX. However DX + BX might have a carry result that should be added to the following CX+AX. Therefore to ensure the carry bit (if there is a carry) is added to the following segment ADC (ADD with Carry) must be used.

So the code for this program will be

ADD DX,BX
ADC CX,AX

4322FFFF16=  0100 0011 0010 0010 1111 1111 1111 11112
4321000116 =  0100 0011 0010 0001 0000 0000 0000 00012


  0100 0011 0010 0010 1111 1111 1111 1111

+0100 0011 0010 0001 0000 0000 0000 0001
-------------------------------------------------
  1000 0110 0100 0100 0000 0000 0000 0000 = 8644000016
-------------------------------------------------

Therefore (check the second set/second command/ADC only)
SF=1 (the sign bit is number 1)
CF=0 (no carry) 
PF=0 (number of 1 is odd)
ZF=0 (result not zero)
AF = 0 (there is carry from bit 3 to bit 4)

Popular Posts

Latest Post from my Other Blog