Reputation: 79
I've been trying to print a new line while also printing the alphabet using assembly language in nasmide for the past few days and can't get it, what I've tried so far has either printed nothing, printed just A or printed a multitude of symbols, Google hasn't been helpful to me so I decided to post here.
My code so far is
CR equ 0DH
LF equ 0AH
main:
mov AH,02H
mov CX,26
mov DL, 'A'
while1:
cmp DL, 'A'
add DL, 01H
int 21H
mov DL, 0DH
mov DL, 0AH
int 21H
cmp DL, 'Z'
je Next
jmp while1
Next:
mov AH,4CH
int 21h
Upvotes: 5
Views: 121430
Reputation: 1
.MODEL SMALL;Code model set to small
.STACK 100H ;Stack memory 100H size
.CODE ;Code starts from here
START: ;Mark start of code segment
INPUT: ;Mark input of code segment
MOV AH, 1 ;AH=1,Single key input
INT 21H ;Input in AL
MOV BL, AL ;BL=AL, Input in BL
OUTPUT: ;Mark output of code segment
MOV AH, 2 ;AH=2,Single key output
MOV DL, 0AH ;DL=0AH, ASCII for newline
INT 21H ;Print DL
MOV DL, 0DH ;DL=0DH, ASCII for carriage return
INT 21H ;Print DL
MOV DL, BL ;DL=BL,Display the input
INT 21H ;Print DL
Exit: ;Mark exit of code segment
MOV AH, 4CH ;4CH = DOS exit fuction. Handover the control to OS and exit program
INT 21H ;Invoke the instruction for interrupt where there function needs to be executed
Upvotes: 0
Reputation: 149
Code for printing new line
MOV dl, 10
MOV ah, 02h
INT 21h
MOV dl, 13
MOV ah, 02h
INT 21h
ascii ---> 10 New Line
ascii ---> 13 Carriage Return
That is code in assembly for new line, code is inspirated with writing machine. Our professor told us the story but I'm not good at english.
Cheers :)
Upvotes: 18
Reputation: 1
Mov Ah,02
Mov dl,42
Int 21
Mov dl,0a ---> next line
Int 21
Mov dl,43
Int 21
Output:
B
C
Upvotes: 0
Reputation: 157
100% works.
CR equ 0DH
LF equ 0AH
main:
mov DL, 'A'
while1:
mov AH,02H ;print character
int 21H
mov BL, DL ;store the value of DL before using DL for print new line
mov DL, 10 ;printing new line
mov AH, 02h
int 21h
mov DL, 13
mov AH, 02h
int 21h
mov DL, BL ;return the value to DL
cmp DL, 'Z'
je exit
add DL, 1 ;store in DL the next character
jmp while1
exit:
mov AH,4CH
int 21h
Upvotes: 4
Reputation: 59
you could just use the
mov ah, 02h
mov dl, 13
int 21h
mov dl, 10
int 21h
ret
but declare it as a proc at the bottom of your "main endp" you can name that function newline and call it where ever you need a newline
Upvotes: 0
Reputation: 21409
Well, first off:
mov DL, 0DH
mov DL, 0AH
int 21H
Isn't going to do you any good. You load 0Dh into DL and then immediately overwrite it with 0Ah without ever having used the first value... You need to make your call (int 21h) on BOTH characters...
Furthermore, you're using DL for newlines overwrites the prior use for the character... You need to save and restore that value as necessary.
Upvotes: 3