Exercise 3      Name       ____________________   Points __/27

1. (4 points) Perform the following arithmetic representing the numbers using 6-bits. Use two's complement representation for negative numbers. An example has been completed.

    -15  =  110001        a)    31                        b)    -13
    +13    +001101             -14                              +12
     -2    0111110                                
                                             1's        2's
                           31 =  011111  = 011111  =  011111
                          -14   -001110   +110001    +110010
                           17    010001   1010000    1010001     
                                               +1
                                           010001

                                              1's      2's
                           -13  = -001101 = 110010 = 110011
                           +12    +001100  +001100  +001100
                            -1    -000001   111110   111111

2. ( 9 points)    Perform the following additions involving 8-bit binary integers in the modulo 28 number system. Give result register and CF, OF, SF, and ZF flag values. A solved example is given.

Example

Mov Al, 00111011B        Mov Bl, 10110101B      Mov Bh, 10110011B      Mov Ah, 11101011B
Add Al, 01011001B        Add Bl, 00110011B      Add Bh, 01011011B      Add Ah, 11110010B
 00111011           a)    10110101          b)     10110011       c)     11101011
+01011001                +00110011                +01011011             +11110010
010010100                011101000                100001110             111011101

Al=10010100              Bl=11101000               Bh=00001110             Ah=11011101
CF=0                     CF= 0                     CF= 1                   CF= 1
OF=1                     OF= 0                     OF= 0                   OF= 0
ZF=0                     ZF= 0                     ZF= 0                   ZF= 0
SF=1                     SF= 1                     SF= 0                   SF= 1

3. ( 9 points)    Perform the following subtractions involving 8-bit binary integers in the modulo 28 number system by adding the two's complement of the subtrahend to the minuend. Give result register and CF, OF, SF, and ZF flag values. Remember that CF is complemented for subtraction. A solved example is given.

Example

Mov Ah, 00111011B
Sub Ah, 01011001B               2's Comp
                                               Ah=11100010
 00111011        59             00111011       CF=1
-01011001   =   -89     =>     +10100111       OF=0
                -30            011100010       ZF=0
                                               SF=1
    Mov Ah, 10110101B    Mov Ch, 10110011B          Mov Dh, 11101011B
    Sub Ah, 00110011B    Sub Ch, 01011011B          Sub Dh, 11110010B
a)     10110101        b)     10110011            c)     11101011
      -00110011              -01011011                  -11110010
      110000010              101011000                  011111001
        Ah=10000010            Ch=01011000               Dh=11111001
        CF= 0                  CF= 0                     CF= 1
        OF= 0                  OF= 1                     OF= 0
        ZF= 0                  ZF= 0                     ZF= 0
        SF= 1                  SF= 0                     SF= 1

4. ( 5 points)    Determine the value of the registers. The program listing contains the offsets of the data definitions.

 00000000			.data
 00000000 41 20 41 22		byteArray   BYTE  'A', 32, 41h, 00100010b

 00000004 48 65 6C 6C 6F	helloWorld BYTE "Hello World",0
	   20 57 6F 72 6C
	   64 00

 00000010 0001 0002 0003	wordArray	WORD   1,2,3,4,5	; array of words
	   0004 0005

 0000001A 00000010 R		ptrWordArray    DWORD  wordArray

 00000000			.code
 00000000			main PROC
 00000000  BE 00000004 R		mov		eSi, OFFSET helloWorld		
 00000005  8A 06				mov		al, [eSi]			; al = 48

 00000007  BF 00000003			mov		eDi, 3			
 0000000C  8A A7 00000004 R		mov		ah, helloWorld[ eDi ]	; ah = 6C

 00000012  8B 1D 0000001A R		mov		eBx, ptrWordArray		; eBx = 00000010
 00000018  66| 8B 0B			mov		cx, [ eBx ]			; cx = 0001
					
 0000001B  66| 8B 53 04			mov		dx, [ eBx + 4]		; dx = 0003
					
					exit
 00000026			main ENDP