Monday, 17 June 2013

54. SEPARATING POSITIVE & NEGATIVE NUMBERS


MOV SI,1100
      MOV CX,0A
      MOV AL,00
L2: MOV BX,[SI]
      ADD BX,00H
      JS L1
      INC SI
      INC AL

      DEC CX
      JNZ L2
      JMP L3
L1: INC SI
      INC AH
      DEC CX
      JNZ L2
L3: HLT


Need the code??

53. MATRIX MULTIPLICATION IN 8086


MOV SI,1000
       MOV BP,1020
       MOV DI,1050
L2:  MOV CX,00
L1:  MOV AL,[SI]
       MOV BL,[BP]
       MUL BL
       ADD CX,AX
       ADD BP,03
       INC SI
       CMP BP,1029
       JB L1
       SUB SI,03
       SUB BP,08
       ADD DI,02
       CMP BP,1023
       JB L2
      ADD SI,03
      SUB BP,03
      CMP DI,1051
       JB L2
HLT


Need the code??

52. CODE CONVERSION IN 8086


ASCII ADJUSTMENT INSTRUCTIONS


CODE SEGMENT
ASSUME CS:CODE
START: MOV AX,31H
ADD AX,39H
AAA
ADD AX,3030H
MOV BL,9
MOV AX,0702H
AAD

DIV BL
MOV AL,5
MOV CL,5
MUL CL
AAM
ADD AX,3030H
MOV AX,38H
SUB AX,31H
AAS
AX,3030H
MOV AH,4CH
INT 21H
CODE ENDS
END START


BINARY TO BCD CONVERSION



DATA SEGMENT
BIN DW 01A9H
BCD DB 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,BIN
MOV CL,64H
DIV CL
MOV BCD+1,AL
MOV AL,AH
MOV AH,00H
MOV CL,0AH
DIV CL
MOV CL,04
ROR AL,CL
ADD AL,AH
MOV AH,4CH
INT 21H
CODE ENDS
END START


Input: binary--------01A9
Output: bcd------------425


BCD TO BINARY CONVERSION



DATA SEGMENT
BCD DW 27H
BIN DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,BCD
AND AX,07H
MOV BX,AX
MOV AX,BCD
AND AX,0F0H
MOV CX,0AH
MUL CX
ADD AX,BX
MOV BIN,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START


Input: BCD-------------27
Output:------------------1B



Need the code??

51. BLOCK TRANSFER IN 8086


DATA SEGMENT
X DB 01H,02H,03H,04H,05H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV CX,05H
LEA SI,X+04
LEA DI,X+04+03
UP: MOV BL,[SI]
MOV [DI],BL
DEC SI
DEC DI
DEC CX
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START


Need the code??

50. BLOCK INTERCHANGE IN 8086


DATA SEGMENT
X DB 01H,02H,03H,04H,05H
Y DB 11H,12H,13H,14H,15H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV CX,05H
LEA SI,X
LEA DI,Y
UP: MOV BL,[SI]
MOV AL,[DI]
MOV [SI],AL
MOV [DI],BL
INC SI
INC DI
DEC CX
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START


Need the code??

49. 16 & 32-BIT SUBTRACTION IN 8086


16-BIT SUBTRACTION

DATA SEGMENT
NUM DW 4567H,2345H
DIF DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME
CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
CLC
                             
LEA SI,NUM                          
MOV AX,[SI]                         
SBB AX,[SI+2]                       
MOV DIF,AX                                   
MOV AH,4CH
INT 21H
CODE ENDS
END START


INPUT: 4567H,2345H
OUTPUT:2222


32-BIT SUBTRACTION

DATA SEGMENT
NUM1 DW 2345H,6762H
NUM2 DW 1111H,1111H
DIF DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,NUM1
LEA DI,NUM2
MOV AX,[SI]
MOV BX,[DI]
SUB AX,BX
MOV DIF,AX
INC SI
INC SI
INC DI
INC DI
MOV AX,[SI]
MOV BX,[DI]
SBB AX,BX MOV DIF+2,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START

INPUT: 23456762,-11111111
OUTPUT:12345651

INPUT:11111111,-23451234
OUTPUT:EDCBFEDD


Need the code??

48. 16-BIT MULTIPLICATION IN 8086


16-BIT MULTIPLICATION FOR UNSIGNED NUMBERS


DATA SEGMENT
NUM DW 1234H,1234H
PROD DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,NUM
MOV AX,[SI]
MOV BX,[SI+2]

MUL BX
MOV PROD,AX
MOV PROD+2,DX
MOV AH,4CH
INT 21H
CODE ENDS
END START


INPUT: Multiplicand- 1234H,
           Multiplier-   1234H


OUTPUT: DX-01 4B
              AX-54 90




16-BIT MULTIPLICATION FOR SIGNED NUMBERS




DATA SEGMENT
NUM DW -2,1
PROD DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,NUM
MOV AX,[SI]
MOV BX,[SI+2]
IMUL BX
MOV PROD,AX
MOV PROD+2,DX
MOV AH,4CH
INT 21H
CODE ENDS
END START


INPUT: Multiplicand- -2,
           Multiplier-   1
OUTPUT: DX – FF FF
               AX – FF FE



Need the code??

47. 16-BIT DIVISION IN 8086


16-BIT DIVISION FOR SIGNED NUMBERS


DATA SEGMENT
NUM1 DW 4567H,2345H
NUM2 DW 4111H
QUO DW 2 DUP(0)
REM DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA

MOV DS,AX
MOV AX,NUM1
MOV DX,NUM1+2
DIV NUM2
MOV QUO,AX
MOV REM,DX
MOV AH,4CH
INT 21H
CODE ENDS
END START


INPUT:       Dividend - 23454567,
                 Divisor - 4111,
OUTPUT:    AX – 8AC5H (quotient);
                 DX – 0952H (reminder);




16-BIT DIVISION FOR UNSIGNED NUMBERS



DATA SEGMENT
NUM1 DW 4567H,2345H
NUM2 DW 4111H
QUO DW 2 DUP(0)
REM DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM1
MOV DX,NUM1+2
CWD
IDIV NUM2
MOV QUO,AX
MOV REM,DX
MOV AH,4CH
INT 21H
CODE ENDS
END START


INPUT:   Dividend - -44444444,
 Divisor - 2222,
0UTPUT:  AX – FE (quotient);
               DX – FF (reminder)



Need the code??

46. 16 & 32 BIT ADDITION IN 8086


16-BIT ADDITION


DATA SEGMENT
NUM DW 1234H, 0F234H
SUM DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM



MOV BX,0H
ADD AX,NUM+2
JNC DOWN
INC BX
DOWN: MOV SUM,AX
MOV SUM+2,BX
MOV AH,4CH
INT 21H
CODE ENDS
END START


INPUT :     1234H,   F234H
OUTPUT : 10468H




32-BIT ADDITION



DATA SEGMENT
NUM1 DW 0FFFFH,0FFFFH
NUM2 DW 1111H,1111H
SUM DW 4 DUP(0)
dATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,NUM1
ADD AX,NUM2
MOV SUM,AX
MOV AX,NUM1+2
ADC AX,NUM2+2
JNC DOWN
MOV SUM+4,01H
DOWN: MOV SUM+2,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START


INPUT:     0FFFFFFFFH,      011111111H
OUTPUT: 0111111110H




32-BIT ADDITION USING DD DIRECTIVE



DATA SEGMENT
NUM1 DW 12345678H
NUM2 DW 12345678H
SUM DW 3 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
LEA SI,NUM1
LEA DI,NUM2
MOV AX,[SI]
ADD AX,[DI]
MOV CX,[SI+2]
ADC CX,[DI+2]
JNC DOWN
MOV SUM+4,01H
DOWN:MOV SUM,AX
MOV SUM+2,CX
MOV AH,4CH
INT 21H
CODE ENDS
END START


INOUT:      12345678H,     12345678H
OUTPUT:   2468ACF0H


Need the code??

45. 8-BIT DIVISION IN 8086


8-BIT DIVISION FOR UNSIGNED NUMBERS


DATA SEGMENT
NUM1 DB 72H,
NUM2 DB 02H
QUO DB 1 DUP(0)
REM DB 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,NUM1

MOV AH,0H
DIV NUM2
MOV QUO,AL
MOV REM,AH
MOV AH,4CH
INT 21H
CODE ENDS
END START


INPUT:        Dividend - 72H,
                    Divisor - 02 H,
0UTPUT:     AL - 39H (quotient);
                    AX - 00H (reminder);


INPUT:       Dividend - 55H,
                   Divisor - 04 H,
0UTPUT:    AL - 15H (quotient);
                   AX - 01H (reminder);




8-BIT DIVISION FOR SIGNED NUMBERS



DATA SEGMENT
NUM1 DB -10
NUM2 DB 02
QUO DB 1 DUP(0)
REM DB 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,NUM1
CBW
IDIV NUM2
MOV QUO,AL
MOV REM,AH
MOV AH,4CH
INT 21H
CODE ENDS
END START




INPUT:   Dividend - -10
                Divisor - 03
0UTPUT:  AL – FDH (quotient);
                 AX – FF H (reminder) ; Result is in two complement form


Need the code??