Skip to content

Instantly share code, notes, and snippets.

@alexsunday
Created December 1, 2019 09:06
Show Gist options
  • Save alexsunday/174c85fe1f16d3f3694033d44f6fb32b to your computer and use it in GitHub Desktop.
Save alexsunday/174c85fe1f16d3f3694033d44f6fb32b to your computer and use it in GitHub Desktop.
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
; dh 行号,dl 列号,cl 颜色 ds:si 指向字符串首地址
mov dh, 8
mov dl, 3
mov cl, 00000010B
call show_str
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
show_str:
; 显示字符串,show_str 在指定位置,使用指定颜色,显示0结尾的字符串
; dh 行号,dl 列号,cl 颜色 ds:si 指向字符串首地址
; 0 行 第0列 偏移为 0
; 1 行 第0列 偏移为 160 第 N 行 m 列,偏移为 160 * n + 2 * m
mov ax, 0B800H
mov es, ax
; 计算首地址 di
mov al, dh
mov ah, 160
mul ah
push ax
mov al, dl
mov ah, 2
mul ah
pop di
add di, ax
mov ah, cl
mov cx, 0
show_byte:
mov al, ds:[si]
mov es:[di], ax
mov cl, al
jcxz show_end
inc si
add di, 2
jmp show_byte
show_end:
ret
quit:
mov ax, 4C00H
int 21H
code ends
end start
@alexsunday
Copy link
Author

图片

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment