📄 !_test.asm
字号:
.model small
.386
.stack 200h
;----------------------------------------------------
.data
;variables used in _call_readi_ routine
buf db 64 dup(?)
count dw ?
;return values
_return dw ?
;global and _main variables
main@a dw ?
main@b dw ?
;----------------------------------------------------
.code
;_MAIN PROC
start proc far
mov ax, @data
mov ds, ax
;
;
;
mov ax, 1
push ax
pop ax
mov main@b, ax
push ax
pop ax
mov main@a, ax
;start of if statement
;if conditions
mov ax, main@a
push ax
mov ax, main@b
push ax
pop bx
pop ax
sub ax, bx
cmp ax, 0
je __eq@@1
mov ax, 0
jmp __eq@@2
__eq@@1:
mov ax, 1
__eq@@2:
push ax
pop ax
cmp ax, 0
je __not@@3
mov ax, 0
jmp __not@@4
__not@@3:
mov ax, 1
__not@@4:
push ax
pop ax
cmp ax, 0
je L5
;if statements
;printf statement
push ax
push dx
mov ah, 2
mov dl, 06eh
int 21h
mov dl, 06fh
int 21h
mov dl, 074h
int 21h
mov dl, 020h
int 21h
mov dl, 065h
int 21h
mov dl, 071h
int 21h
mov dl, 075h
int 21h
mov dl, 061h
int 21h
mov dl, 06ch
int 21h
mov dl, 00ah
int 21h
mov dl, 00dh
int 21h
pop dx
pop ax
;end of printf statement
jmp L6
L5:
;else statements
;printf statement
push ax
push dx
mov ah, 2
mov dl, 065h
int 21h
mov dl, 071h
int 21h
mov dl, 075h
int 21h
mov dl, 061h
int 21h
mov dl, 06ch
int 21h
mov dl, 00ah
int 21h
mov dl, 00dh
int 21h
pop dx
pop ax
;end of printf statement
L6:
;end of if statement
mov ax, 4c00h
int 21h
start endp
;----------------------------------------------------
; GENERAL PRUPOSE ROUTINES
;----------------------------------------------------
; FOR READI
;----------------------------------------------------
;input a decimal, result in AX
_call_readi_ proc near pascal uses bx cx dx si
mov count, 0
readi@next:
mov ah, 7
int 21h
cmp al, '-'
je readi@onCHAR
cmp al, '+'
je readi@onCHAR
cmp al, 08h ;DEL
je readi@onDEL
cmp al, 0dh ;CR
je readi@onCR
cmp al, '0'
jb readi@next
cmp al, '9'
ja readi@next
readi@onCHAR:
cmp count, 63
jae readi@next
;process the key input, and show it on screen
mov si, count
inc count
mov buf[si], al
mov dl, al
mov ah, 02h
int 21h
jmp readi@next
readi@onDEL:
call keydel
jmp readi@next
readi@onCR:
mov ah, 2
mov dl, 0ah
int 21h
mov dl, 0dh
int 21h
mov si, count
mov buf[si], 0
call str2dec
ret
_call_readi_ endp
;----------------------------------------------------
;set the cursor in DX
set_cur proc near pascal uses ax bx
mov bh, 0
mov ah, 02h
int 10h
ret
set_cur endp
;----------------------------------------------------
;read current cursor to DX
read_cur proc near pascal uses ax bx cx
mov bh, 0
mov ah, 03h
int 10h
ret
read_cur endp
;----------------------------------------------------
;procedure for key DEL
keydel proc near pascal uses bx cx dx
cmp count, 0
jle keydel@ret
dec count
call read_cur
dec dl
call set_cur
mov bh, 0
mov al, 20h
mov cx, 1
mov ah, 0ah
int 10h
keydel@ret:
ret
keydel endp
;----------------------------------------------------
;result in AX
str2dec proc near pascal uses bx cx dx si
local minus:byte
;init
mov minus, 0
mov ax, 0
mov bx, 10
mov cx, 0
;
cmp count, 0
je str2dec@ret
mov si, 0
cmp buf[si], '-'
je str2dec@onMINUS
cmp buf[si], '+'
je str2dec@onPLUS
str2dec@next:
cmp buf[si], '0'
jb str2dec@complete
cmp buf[si], '9'
ja str2dec@complete
mul bx
mov cx, ax
mov al, buf[si]
sub al, '0'
mov ah, 0
add ax, cx
inc si
jmp str2dec@next
str2dec@onMINUS:
mov minus, 1
inc si
jmp str2dec@next
str2dec@onPLUS:
inc si
jmp str2dec@next
str2dec@complete:
cmp minus, 1
jne str2dec@ret
mov cx, ax
mov ax, 0
sub ax, cx
str2dec@ret:
ret
str2dec endp
;----------------------------------------------------
; FOR WRITEI
;----------------------------------------------------
;show decimal in BX
_call_showi_ proc near pascal uses ax cx dx
local can_show:byte
mov can_show, 0
cmp bx, 0
jge show@show
mov ax, bx
mov bx, 0
sub bx, ax
mov ah, 2
mov dl, '-'
int 21h
show@show:
mov cx, 10000d
cmp bx, cx
jb show@1
mov can_show, 1
call dec_div
show@1:
mov cx, 1000d
cmp can_show, 1
je show@2
cmp bx, cx
jb show@3
mov can_show, 1
show@2:
call dec_div
show@3:
mov cx, 100d
cmp can_show, 1
je show@4
cmp bx, cx
jb show@5
mov can_show, 1
show@4:
call dec_div
show@5:
mov cx, 10d
cmp can_show, 1
je show@6
cmp bx, cx
jb show@7
mov can_show, 1
show@6:
call dec_div
show@7:
mov cx, 1d
call dec_div
ret
_call_showi_ endp
;----------------------------------------------------
dec_div proc near pascal uses ax
mov ax, bx
mov dx, 0
div cx
mov bx, dx
mov dl, al
add dl, 30h
mov ah, 2
int 21h
dec_div@ret:
ret
dec_div endp
;----------------------------------------------------
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -