write a program in 8086 with these demands:
1. input 2 numbers from the user (no need to check the integrity of the input)
2. Subtraction and ADD action between the 2 numbers
3. divide action between the 2 numbers
4. muliplication action between the 2 numbers
5. print the result on the screen in DECIMAL or BINARY or HEXA depending on choice
how it works: the program will first get a key press and will act on that choice
'0' - input 2 numbers
'1' - ADD action
'2' - Substraction action
'3' - Multiplication
'4' - divide
'5' - print
__________________
D - print in decimal
H - print in hexa
B - print in binary
'0' - Exit program
Im stuck on making this program... any one can help? this are the codes i did so far but got stuck on how to progress
; multi-segment executable file template.
data segment
; add your data here!
NUM DW 1254
STR DB 16 DUP (20H),0AH,0DH,'$'
D DW 10
O DW 8
B DW 2
H DW 16
pkey db "press any key...$"
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
; add your code here
CALL PRINT_HEX
CALL PRINT_DEC
CALL PRINT_OCT
CALL PRINT_BIN
CALL SOF
;==========================
PRINT_DEC PROC
MOV BX , 15
MOV AX , NUM
L1: MOV DX , 0
DIV D
MOV STR[BX] , 20H
ADD STR[BX] , DL
ADD STR[BX] , 10H
DEC BX
CMP AX , 0
JNZ L1
LEA DX , STR
MOV AH , 9
INT 21H
ret
PRINT_DEC ENDP
;==========================
PRINT_HEX PROC
MOV BX , 15
MOV AX , NUM
L3: MOV DX , 0
MOV STR[BX] , 20H
DIV H
CMP DL , 9
JLE L11
ADD STR[BX] , 7
L11: ADD STR[BX] , DL
ADD STR[BX] , 10H
DEC BX
CMP AX , 0
JNZ L3
LEA DX , STR
MOV AH , 9
INT 21H
ret
PRINT_HEX ENDP
;==========================
PRINT_BIN PROC
MOV BX , 15
MOV AX , NUM
L2: MOV DX , 0
DIV B
MOV STR[BX] , 20H
ADD STR[BX] , DL
ADD STR[BX] , 10H
DEC BX
CMP AX , 0
JNZ L2
LEA DX , STR
MOV AH , 9
INT 21H
ret
PRINT_BIN ENDP
;=============================
PRINT_OCT PROC
MOV BX , 15
MOV AX , NUM
L8: MOV DX , 0
DIV O
MOV STR[BX] , 20H
ADD STR[BX] , DL
ADD STR[BX] , 10H
DEC BX
CMP AX , 0
JNZ L8
LEA DX , STR
MOV AH , 9
INT 21H
ret
PRINT_OCT ENDP
;=============================
SOF:
lea dx, pkey
mov ah, 9
int 21h ; output string at ds:dx
; wait for any key....
mov ah, 1
int 21h
mov ax, 4c00h ; exit to operating system.
int 21h
ends
end start ; set entry point and stop the assembler.
name Calc
data segment
ETR DB 0AH,0DH,'$'
NUM1 DB 0
NUM2 DB 0
RESULT DB 5 DUP ('0'),'$'
TEMP DB 10
data ends
sseg segment stack
sseg ends
code segment
assume cs:code, ds:data, ss:sseg
start:
mov ax ,data
mov ds, ax
CALL GET_NUMBER
MOV NUM1 , CL
CALL GET_NUMBER
MOV NUM2 , CL
MOV AL , NUM1
ADD AL , NUM2
CALL PRINT_DEC
JMP SOOF
;---------------------------
GET_NUMBER :
MOV DX , 0
MOV CL , 0
L1: MOV AH , 1
INT 21H
CMP AL , 0DH
JE END_INPUT
AND AL , 0FH
MOV CH , AL
MOV AL , CL
MUL TEMP
ADD AL , CH
MOV CL , AL
JMP L1
END_INPUT:
RET
;-----------------------
PRINT_DEC:
MOV SI , 4
L2: MOV AH , 0
CMP AL , 0
JE END_PRNDC
DIV TEMP
ADD RESULT[SI] , AH
DEC SI
JMP L2
END_PRNDC :
LEA DX , ETR
MOV AH , 9
INT 21H
LEA DX , RESULT
MOV AH , 9
INT 21H
RET
;-----------------------
What I have tried:
i tried looking online on how to get input from user and make this menu i need but i cant figure it out.. endless of hours on that tiny project and now stuck with frustration..