Created
December 1, 2019 08:51
-
-
Save alexsunday/331877879bb41b79d9b74e22234e7b20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assume cs:code,ds:data,ss:stack | |
data segment | |
db 128 dup(0) | |
data ends | |
stack segment stack | |
db 128 dup(0) | |
stack ends | |
code segment | |
start: | |
mov ax, stack | |
mov ss, ax | |
mov sp, 128 | |
mov ax, data | |
mov ds, ax | |
mov si, 0 | |
mov dx, 0 | |
mov ax, 1243 | |
call dtoc | |
jmp quit | |
dtoc: | |
; 将 word 型数据转变为 十进制字符串 ax word型数据,ds:si 结果字符串首地址 | |
push ax | |
push bx | |
push cx | |
push dx | |
push si | |
mov bx, 0 | |
div_proc: | |
mov cx, 10 | |
div cx | |
inc bx | |
add dx, 30H | |
push dx | |
mov dx, 0 | |
mov cx, ax | |
jcxz div_end | |
jmp div_proc | |
div_end: | |
; 除完后,将结果从栈中取出 | |
mov cx, bx | |
get_result: | |
pop bx | |
mov ds:[si], bl | |
inc si | |
loop get_result | |
; 最后写一个 0 | |
mov byte ptr ds:[si], 0 | |
pop si | |
pop dx | |
pop cx | |
pop bx | |
pop ax | |
ret | |
quit: | |
mov ax, 4C00H | |
int 21H | |
code ends | |
end start |
Author
alexsunday
commented
Dec 1, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment