繁体   English   中英

如何在EMU8086中动态打印消息

[英]How to print a message dynamically in EMU8086

这是我的代码;

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  

我该怎么做呢??
谢谢大家!!!

您可以将行号的char值与主要消息连接起来:

org 100h

mov cx,5
loop1:  
        call DISPLAY
        dec cx
        cmp cx,0
        ja loop1
        jmp Exit

DISPLAY proc
 MOV AH,09
 MOV BX,  offset SCREEN 
 MOV AL,CL
 NEG AL
 ADD AL,'0'+6
 MOV [BX+7],AL  
 MOV DX,BX
 INT 21h
 RET
DISPLAY ENDP         

Exit:
ret

SCREEN DB 'Number  ',0x0A,0x0D,'$'


编辑:

这是一种更通用的形式,类似于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) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM