int 21h
endm
.model small
.stack
.data
arr db 20 dup(0)
temp db 20 dup(0)
res dw 0000h
msg0 db 10,13,'------MENU------$'
msg1 db 10,13,'1.INPUT $'
msg2 db 10,13,'2.SUCC_ADD $'
msg3 db 10,13,'3.ADD-SHIFT $'
msg4 db 10,13,'4.EXIT $'
msg5 db 10,13,'NO: $'
msg6 db 10,13,'RESULT: $'
msgn db 10,13,'$'
.code
main proc
mov ax,@data
mov ds,ax
m: disp msg0
disp msg1
disp msg2
disp msg3
disp msg4
mov ah,01h
int 21h
cmp al,'1'
je inp
cmp al,'2'
je succad
cmp al,'3'
je adsht
cmp al,'4'
je ex
ex: mov ax,4c00h
int 21h
inp: call input
jmp m
succad: call succ_add
call hex
jmp m
adsht: call add_shift
call hex
jmp m
endp main
;input proc
input proc near
mov ch,02h
lea si,arr
a1:
disp msg5
lea bx,temp
mov cl,00h
a2:
mov ah,01h
int 21h
cmp al,0Dh
je a3
inc cl
sub al,30h
mov [bx],al
inc bx
jmp a2
a3:
lea bx,temp
mov ax,0000h
mov di,10
a4:
add ax,[bx]
cmp cl,01h
je a5
mul di
dec cl
inc bx
jmp a4
a5:
mov [si],ax
inc si
dec ch
jnz a1
ret
endp
;successive addition method
succ_add proc near
mov ax,0000h
mov cx,0000h
lea si,arr
mov ax,[si]
inc si
mov cx,[si]
mov ch,00h
mov ah,00h
mov dx,0000h
m1:
add dx,ax
dec cx
jnz m1
mov res,dx
ret
endp
;add and shift method
add_shift proc near
mov ax,0000h
mov cx,0000h
lea si,arr
mov ax,[si]
inc si
mov cx,[si]
mov ch,00h
mov ah,00h
mov dx,0000h
m2:
test cx,1
jz m3
add dx,ax
m3:
shr cx,1
shl ax,1
;if cx is not 0
jnz m2
mov res,dx
ret
endp
;hex to deci conv
hex proc near
disp msg6
mov ax,res
mov cx,0000h
mov bx,000Ah
d1: mov dx,0000h
div bx
push dx
inc cx
cmp ax,00h
jne d1
d2:
pop dx
add dl,30h
mov ah,02h
int 21h
dec cx
jnz d2
ret
endp
end
No comments:
Post a Comment