问题描述
My name is xxxxx
My rollnumber is yyyyy
What is Your name
到目前为止,我已经完成了打印这些字符串的操作,但是在字符串的开头并没有得到这些空格。
我的代码rn:
display macro data
mov ah,9
lea dx,msg1
int 21h
mov ah,msg2
int 21h
mov ah,msg3
int 21h
endm
.model small
.stack 100h
.data
msg1 db "My name is Adeena Lathiya $"
msg2 db 0ah,0dh,"My roll number is SE-009 $"
msg3 db 0ah,"What is Your name $"
.code
main proc
mov ax,@data
mov ds,ax
display data
main endp
end main
,这显示为:
My name is xxxxx
My rollnumber is yyyyy
What is Your name
请告诉我如何在字符串的开头添加空格
解决方法
...使用仅一个宏定义
确保该任务表明您只能具有1个宏定义,但它不会告诉您仅一次调用该宏!
另外,宏的功能部分来自于当前实现中提及但根本没有使用的可替换参数!
Display 宏
此基本宏使用1个参数: aString 指定消息的地址。
Display MACRO aString
lea dx,aString
mov ah,09h ; DOS.PrintString
int 21h
ENDM
使用方式如下:
mov ax,@data
mov ds,ax
Display msg1
Display msg2
Display msg3
...
msg1 db "My name is Adeena Lathiya",13,10,"$"
msg2 db " My roll number is SE-009","$"
msg3 db " What is Your name $"
^
The required spaces!
将您要查找的空格插入存储的字符串中。
IndentedDisplay 宏
这次宏使用2个参数: Indentation 指定文本前面的空格数,而 aString 指定消息的地址。
IndentedDisplay MACRO Indentation,aString
LOCAL More,Skip
mov cx,Indentation
jcxz Skip
More:
mov dl," "
mov ah,02h ; DOS.PrintChar
int 21h
loop More
Skip:
lea dx,ax
IndentedDisplay 0,msg1
IndentedDisplay 1,msg2
IndentedDisplay 3,msg3
...
msg1 db "My name is Adeena Lathiya","$"
msg2 db "My roll number is SE-009","$"
msg3 db "What is Your name $"
在这里,您要查找的空格将通过运行宏代码插入。