📄 bufprf.asm
字号:
;/++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; printnm is the modify verion of printf, it won't do I/O operating
; just used as a format convertion tools to normalize the line number
; in decimal makes it looks all right.
; The entry points into this file are
; printnm : insert the char to the specified file offset
; printnum : convert the binary to the normalize decimal
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/
include comstruc.inc
include arg.inc
sseg segment stack
db 128 dup (0)
sseg ends
dseg segment para public 'global'
extrn inrtpos:word
dseg ends
cseg segment para public 'code'
assume cs:cseg,ds:dseg,es:dseg,ss:sseg
public printnm
;/============================================================================
;
; printnm
;
;============================================================================/
printnm proc near
push ds
push es
push bp
mov bp,sp
sub sp,8
; stack arranges like this
;
; [bp-2] : bit count of decimal
; [bp-4] : a
; [bp-6] : n
; [bp-8] : b
; initialize the max label bit,
; 5 bit in decimal can expresses
; less than 65535 lines, because
; the integer is only 16 bit
mov word ptr [bp-2],0
mov ax,8[bp]
mov [bp-6],ax ; get n
mov ax,10[bp]
mov [bp-8],ax ; get b
; first we get space printed, 'spnr'
; indicates how many spaces needed
mov cx,spnr
sploop:
cmp cx,0
jz pn1loop
mov ax,20h
push ax
call printnum ; print one space each time
pop ax
dec cx
jmp sploop
pn1loop:
mov ax,[bp-2]
xor dx,dx
mov ax,[bp-6]
mov bx,[bp-8]
div bx
mov [bp-4],ax
xor dx,dx
mov ax,[bp-6]
mov bx,[bp-8]
div bx
add dx,30h ; convert to ascii
push dx
call printnum
pop cx
mov ax,[bp-4]
mov [bp-6],ax
inc word ptr [bp-2]
cmp ax,0
jnz pnmnext1
; if [bp-4] == 0, feed rest room with '0'
mov cx,insertnr
sub cx,[bp-2]
sub cx,spnr
jz goback ; if 5 bit is feed, no '0' can feed
feedloop:
push cx
cmp cx,0
jz goback
mov ax,30h ; '0'
push ax
call printnum
pop ax
pop cx
dec cx
jmp feedloop
goback:
mov sp,bp
pop bp
pop es
pop ds
ret
pnmnext1:
jmp pn1loop
printnm endp
;/============================================================================
;
; printnum
;
;============================================================================/
printnum proc near
push ds
push es
push bp
mov bp,sp
sub sp,2
; stack arranges like this
;
; [bp-2] : ascii to be inserted
mov ax,8[bp]
mov [bp-2],ax
mov al,[bp-2]
mov di,inrtpos
std
stosb
mov inrtpos,di ; save next position
mov sp,bp
pop bp
pop es
pop ds
ret
printnum endp
cseg ends
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -