简体   繁体   中英

Give Space on new line in assembly language

I am new to assembly language. I am given this task to write code for the following output:

Q) Write down the assembly code of following output using Only One Macro definition

My name is xxxxx
 My rollnumber is yyyyy
   What is Your name

So far what I have done is printing these strings, but i am not getting these spaces in the beginning of string.

My code rn:

display macro data    
    
    mov ah,9                    
    lea dx,msg1                 
    int 21h
    
    mov ah,9                    
    lea dx,msg2                 
    int 21h 
    
    mov ah,9                    
    lea dx,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, 0dh, "What is Your name $"   
 
.code
 main proc
    
       mov ax,@data
       mov ds,ax 
       
       display data
       
       main endp
 end main

and this displays the output as:

My name is xxxxx
My rollnumber is yyyyy
What is Your name

please tell me how to add spaces in the beginning of the strings

...using Only One Macro definition

Sure the task says that you can only have 1 macro definition but it doesn't tell you to invoke the macro just the one time!
Also the power of a macro comes partly from its replaceable parameters that your current implementation mentions but doesn't use at all!

The Display macro

This basic macro uses 1 parameter: aString specifies the address of the message.

Display MACRO aString
    lea   dx, aString
    mov   ah, 09h        ; DOS.PrintString
    int   21h
ENDM

Use it like:

    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", 13, 10, "$"
    msg3 db "   What is Your name $"
             ^
             The required spaces!

Here the spaces that you were looking for were inserted in the stored strings .

The IndentedDisplay macro

This time the macro uses 2 parameters: Indentation specifies the number of spaces in front of the text, and aString specifies the address of the message.

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, aString
    mov   ah, 09h        ; DOS.PrintString
    int   21h
ENDM

Use it like:

    mov   ax, @data
    mov   ds, ax
    IndentedDisplay 0, msg1
    IndentedDisplay 1, msg2
    IndentedDisplay 3, msg3

    ...

    msg1 db "My name is Adeena Lathiya", 13, 10, "$" 
    msg2 db "My roll number is SE-009", 13, 10, "$"
    msg3 db "What is Your name $"

Here the spaces that you were looking for will get inserted from running the macro code .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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