这是我的代码;
org 100h
mov cx,5
loop1:
call DISPLAY
dec cx
cmp cx,0
ja loop1
jmp Exit
DISPLAY proc
MOV AH,09
MOV DX, offset SCREEN
INT 21h
RET
DISPLAY ENDP
Exit:
ret
SCREEN DB 'Number 1','$'
此代码将显示五次' Number1'但我想以下列方式打印屏幕;
Number 1
Number 2
Number 3
Number 4
Number 5
我该怎么做? 谢谢大家!!!
答案 0 :(得分:2)
您可以将行号的char值与主消息连接起来:
printf
<小时/> 编辑:
这是一个更通用的表单,类似于%d
函数和支持%s
和org 100h
mov cx,LINES_NUMBER
xor ax,ax
loop_main:
inc ax
mov offset WORD_ARG,ax
pusha
push offset STR_ARG
push offset WORD_ARG
mov si,offset TEXT_FORMAT
mov di,offset OUT_BUFF
call sprintf
mov ah,0x09
mov dx,offset OUT_BUFF
INT 21h
popa
loop loop_main
ret
end:
; sprintf
; si : Source String
; di : Destination String
; You can use %d and %s
sprintf proc
pop cx
start_proc:
mov ah,[si]
cmp ah,'%'
je is_arg
cmp ah,'$'
je exit_proc
mov ah,[si]
mov [di],ah
inc si
inc di
jmp start_proc
is_arg:
inc si
mov ah,[si]
cmp ah,'d'
je add_decimal
cmp ah,'s'
je add_string
mov [di],'!'
inc di
jmp exit_proc
jmp start_proc
add_decimal:
inc si
pop bx
mov ax,[bx]
mov dx,0x8000
and dx,ax
je not_neg
mov [di],'-'
inc di
neg ax
not_neg:
push ax
mov bx,10
push cx
xor cx,cx
ad_count_digits:
xor dx,dx
inc cx
div bx
test ax,ax
jne ad_count_digits
dec cx
mov bx,cx
pop cx
pop ax
xor bh,bh
push bx
add di,bx
mov bx,10
ad_print_digits:
xor dx,dx
div bx
add dl,'0'
mov [di],dl
dec di
test ax,ax
jne ad_print_digits
xor bx,bx
pop bx
add di,bx
add di,2
jmp start_proc
add_string:
inc si
pop bx
insert_string:
mov ah,[bx]
mov [di],ah
inc bx
inc di
cmp ah,'$'
jne insert_string
dec di
jmp start_proc
exit_proc:
mov [di],'$'
push cx
ret
sprintf endp
LINES_NUMBER EQU 5
WORD_ARG DW 0
STR_ARG DB 'People.',0x0A,0x0D,'$'
TEXT_FORMAT DB 'Number %d %s$'
OUT_BUFF DB 0 DUP(32)
(虽然此代码可能不安全!):
{{1}}