【X86組語】作業二
作業二,0~99兩數字加減法
;;;; 程式說明 ;;;;
;; 使用者輸入一算數
GETCHAR MACRO char
push ax
mov ah,01h
int 21h
mov char,al
pop ax
ENDM
PUTCHAR MACRO char
push dx
push ax
mov dl,char
mov ah,02h
int 21h
pop ax
pop dx
ENDM
END_PROCESS MACRO
mov ah,4ch
int 21h
ENDM
.MODEL SMALL
.DATA
values db 2 dup(?)
operator db 1 dup(?)
.STACK
.CODE
main_pro proc far
mov dl,3
count_loop: mov si,0
keyin_loop: GETCHAR bl
cmp bl,'+'
je go_1
cmp bl,'-'
jne continue
go_1: cmp si,0
je invalid
mov [operator],bl
jmp keyin_loop
go_2: mov [operator],bl
jmp finish
continue: call check_num
mov cl,bl
GETCHAR bl
cmp bl,'+'
je go_2
cmp bl,'-'
je go_2
mov al,10
mul cl
mov cl,al
call check_num
add cl,bl
finish: mov [values+si],cl
inc si
cmp si,2
jne keyin_loop
mov al,[values]
mov bl,[values+1]
mov cl,[operator]
cmp cl,'-'
jne do_add
sub al,bl
call print_ans
jmp ok
do_add: add al,bl
call print_ans
ok: dec dl
jnz count_loop
END_PROCESS
main_pro endp
check_num proc far
cmp bl,'0'
jl invalid
cmp bl,'9'
jg invalid
sub bl,'0'
ret
check_num endp
print_ans proc far
PUTCHAR '='
cmp al,100
jb ignore_h
PUTCHAR '1'
sub al,100
ignore_h: mov cl,10
div cl
add al,'0'
add ah,'0'
PUTCHAR al
PUTCHAR ah
call cr_lf
ret
print_ans endp
cr_lf proc far
push ax
push dx
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
pop dx
pop ax
ret
cr_lf endp
invalid: PUTCHAR '!'
END_PROCESS
END
沒有留言:
張貼留言