Search code examples
assemblytasm

Turbo Assembler Multiple Inputs Overlap


I'm new to assembly language and I am having trouble with my code. At first I tried 1 input and then 1 output and it works just fine. But when I try 2 inputs. That's when the problem shows up. When it asks "Gender" input 1 and output 1 seems to overlap it.

I have searched thoroughly and managed to find one that asks the same thing but his/hers was different and I can't seem to understand. I hope someone can help. This is for school.

Full Code:

.model small
.stack 200
.data
    message db "Name: ","$"
    message2 db "Your name is: ","$"
    message3 db "Gender: ","$"
    message4 db "Your name is: ","$"
    BUF DB 100  
    DB 100 DUP("$") 

.code
MOV ax,@data
mov ds,ax

LEA dx,message  
mov ah,09h
int 21h
mov ah,0ah ;
mov dx, offset buf
int 21h

LEA dx,message2 
mov ah,09h
int 21h
LEA DX,BUF  
ADD DX,02   
MOV AH,09H
INT 21H

LEA dx,message3 
mov ah,09h
int 21h
mov ah,0ah 
mov dx, offset buf
int 21h


LEA dx,message4 
mov ah,09h
int 21h
LEA DX,BUF  
ADD DX,02   
MOV AH,09H
INT 21H

MOV AX,4C00H
INT 21H
END

Solution

  • All the printing is done on the same line. In order to advance to the next line you need to print \n\r but of course not like that as those are interpreted by the high-level languages. You need to use their ASCII codes: 13,10. So extend your code (.data section) with this:

    newline db 13,10,"$"
    

    and wherever you want to go to the new line just print that:

     lea dx, newline
     mov ah, 09h
     int 21h
    

    enter image description here

    Also message4 should be "Your gender is: ","$"