📄 squre.asm
字号:
; program calculate the squre of a two bit unsigned integer
; code by brvman 2008/06/02
.model small
.code
.386
start:
mov ax, @data
mov ds, ax
mov es, ax ; for instruction stosb
mov dx, offset prompt
mov ah, 09h ; print string 'input a number:'
int 21h
input:
mov dx, offset buff
mov ah, 0ah ; input two bit unsigned integer
int 21h
mov si, dx
mov al, [si+1]
cmp al, 2
jz atoi
lea dx, error ; print error message
mov ah, 09h
int 21h
jmp input
atoi: ; convert ascii to integer, store the result in register al
mov si, offset buff
mov al, [si+2]
sub al, 30h
shl al, 1
mov ah, al
shl al, 2
add al, ah
mov ah, [si+3]
sub ah, 30h
add al, ah
squre: ; calculate squre
mul al
; mov bx, ax
mov edi, offset result
cld
itoa: ; convert integer to ascii, store the result in memory result
xor dx, dx
mov cx, 1000
div cx
add al, 30h
stosb
mov ax, dx
mov cl, 100
div cl
add al, 30h
stosb
movzx ax, ah
mov cl, 10
div cl
add al, 30h
stosb
mov al, ah
add al, 30h
stosb
print: ;print the result
mov dx, offset output
mov ah, 09h
int 21h
mov dx, offset result
mov si, dx
mov al, [si]
cmp al, 30h
jnz next
inc dx
next:
mov ah, 09h
int 21h
mov ah, 4ch ; exit program
int 21h
.data
prompt db 'Input a number:$'
output db 0dh, 0ah, 'The squre is $'
error db 'Error! Please input a two bit unsigned integer', 0dh, 0ah, '$'
buff db 3, 0, 3 dup(?)
result db 4 dup(?), 0dh, 0ah, '$'
.stack
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -