2)
.MODEL SMALL
.STACK 100H
.DATA
PROMPT_1 DB 'Enter the string : $'
PROMPT_2 DB 0DH,0AH,'The string in reverse order is : $'
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
LEA DX, PROMPT_1 ; load and display PROMPT_1
MOV AH, 9
INT 21H
XOR CX, CX ; clear CX
MOV AH, 1 ; set input function
@INPUT: ; jump label
INT 21H ; read a digit
CMP AL, 0DH ; compare digit with carriage return
JE @END ; jump to label @END if carriage return
PUSH AX ; push the input char to STACK
INC CX ; increment CX
JMP @INPUT ; jump to label @INPUT
@END: ; jump label
LEA DX, PROMPT_2 ; load and display PROMPT_2
MOV AH, 9
INT 21H
MOV AH, 2 ; set output function
@OUTPUT: ; jump label
POP DX ; POP a value from STACK to DX
INT 21H ; display digit
LOOP @OUTPUT ; jump to label @OUTPUT
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
END MAIN
…………………………………………………………………………………………
1)
MY_DATA SEGMENT
NUM1 DB'1234'
NUM2 DB'1235'
UNPK_NUM1 DW ?
UNPK_NUM2 DW ?
MAX_NUM DW ?
MY_DATA ENDS
MY_CODE SEGMENT
ASSUME CS:MY_CODE, DS:MY_DATA
START: MOV AX,MY_DATA
MOV DS, AX
LEA SI, NUM1
MOV AH,[SI]
INC SI
MOV AL,[SI]
AND AH, 0FH
ROL AH, 0FH
ROL AH, 04H
OR AH, AL
INC SI
MOV BH, [SI]
INC SI
MOV BL, [SI]
AND BH, 0FH
AND BL, 04H
ROL BH, 04H
OR BH, BHL
MOV AL, BH
MOV UNPK_NUM1, AX
LEA SI, NUM2
MOV AH, [SI]
AND AH, 0FH
AND AL, 0FH
AND AH, 04H
ROL AH, 04H
OR AH, 04H
INC SI
MOV BH, [SI]
INC SI
MOV BL, [SI]
AND BH, 0FH
AND BL, 0FH
ROL BH, 04H
OR BH, 04H
MOV AL, BH
MOV UNPK_NUM2, AX
CMP AX, BX
JA LI
MOV MAX_NUM, BX
JMP L2
L1: MOV MAX_NUM, AX
L2: INT 21H
MY_CODE ENDS
END START
…………………………………………………….
3)
MY DATA SEGMENT
BLANK_MEMORY_BLOCK DB 2501H DUP(?)
DIVIDEND DW 105H; 16 BIT NUMBER STORED ON 2501H AND 2502
DIVISOR DB 10H ; 8 BITDIVISOR ON 2503H
QUOTIENT DB ? ; 8 BIT QUOTIENT ON 2504H
REMEAINDER DB ?
MY_DATA ENDS
MY_CODE SEGMENT
ASSUME CS: MY_CODE, DS: MY_DATA
START: MOV AX, MY_DATA
MOV DS, AX
MOV AX, DIVIDENT
MOV BL, DIVISOR
DIV BL
MOV QUOTIENT, AL
MOV REMAINDER, AH
INT 21H
MY_CODE ENDS
END START
…………………………………………………………………………..
4)
MY_DATA SEGMENT
X DW 2H
FLAG DB 0
RESULT DW?
MY_DATA ENDS
MY_CODE SEGMENT
ASSUME CS: MY_CODE, DS: MY_DATA
START: MOV AX, MY_DATA
MOV DS, AX
MOV AL, FLAG
CMP AL, 0
JZ L1
MOV AX, X
MUL AX
MOV BL, 6
MUL BL
MOV BX, AX
MOV CL, 5
MOV AX, X
MUL CL
ADD AX, 9
ADC AX, BX
JMP L2
L1: MOV AX, X
MUL AX
MOV BL, 4MUL BL
ADD AX, 7
L2: MOV RESULT, AX
INT 21H
MY_CODE ENDS
END START
……………………………………………………………………………….
1)
1)
;to view the bcd click on the view and file variables that display
;if you change the string then three different location you change it
org 100h
jmp start
include 'emu8086.inc'
string db '1284' ; if changes then 3 location change
string1 db '1235' ; if changes then 3 location change
packed_bcd dw ?
packed_bcds dw ?
start:
lea bx, string
lea di, packed_bcd
call pack_to_bcd_and_binary
lea bx, string1
lea di, packed_bcds
call pack_to_bcd_and_binary
mov ax,1284 ; if changes then 3 location change
mov bx,1235 ; if changes then 3 location change
cmp ax,bx
je equal
cmp ax,bx
jg first
cmp ax,bx
jl second
equal:
Print '0'
jmp exit
first:
Print '1284'; if changes then 3 location change
jmp exit
second:
print '1235' ; if changes then 3 location change
jmp exit
exit:
ret ;
; subroutine written in 8086 assembly language that can be used for converting a string of number (max of 4
ascii digit) to equivalent packed
; bcd digits.
input parameters:
; bx - address of source string (4 ascii digits).
; output:
; di - must be set to address for packed bcd (2 bytes).
pack_to_bcd_and_binary proc near
pusha
; point to 2 upper digits of packed bcd:
; (assumed that we have 4 digits)
add di, 1
; loop only for 2 because every time we
; read 2 digits (2 x 2 = 4 digits)
mov cx, 2
; reset packed bcd:
mov word ptr [di], 0
; to convert a char (0..9) to digit we need
; to subtract 48 (30h) from its ascii code,
; or just clear the upper nibble of a byte.
; mask: 00001111b (0fh)
next_digit:
mov ax, [bx] ; read 2 digits.
and ah, 00001111b
and al, 00001111b
; 8086 and all other Intel's microprocessors store less
; significant byte at lower address.
xchg al, ah
; move first digit to upper nibble:
shl ah, 4
; pack bcd:
or ah, al
; store 2 digits:
mov [di], ah
; next packed bcd:
sub di, 1
; next word (2 digits):
add bx, 2
loop next_digit
popa
ret
pack_to_bcd_and_binary endp