Some weird character printing with int 10h

Started by
4 comments, last by SiCrane 11 years, 9 months ago
Alright, I think I've seen a solution to this somewhere accidentally at one point, but now when I need it, I can't find it. Also in case the people that were helping me out with Assembly before are wondering why I'm doing 16 bit as opposed to 32 bit, I had a really hard time reading through all of the text, and I wanted to just get to the meat of the programming instead of the background behind it, so I went back to 16 bit, where there's many more resources. I learn best by actually working with what I'm trying to learn.

Well, with that out of the way, here's a picture of the problem I'm having:

16ASM.png

As you can see there's some kind of weird character at the end of "Hello world."

If I remember correctly, this has something to do with unicode and ASCII, I just don't remember how to fix it. Here is my code:


ORG 100h
USE16
main: ;Main program start
mov al, 12h ;Set video mode
int 10h
mov bl, 01h ;Bios color blue for text
mov si, testString ;Move string to si register
call printString ;Call printString function
mov ax, 4c00h ;Appropriate exit code for DOS
int 21h ;Exit DOS
testString db 'Hello world.' ;Defined bytes for a string
printString: ;printString function start
mov ah, 0Eh
.pS_Method: ;Printing character method
lodsb ;Update character from string in si register
cmp al, 0 ;If done, al will be 0
je .pS_Completed ;If al is equal to 0, this will jump to the completion code to return
int 10h ;Otherwise, output character
jmp .pS_Method ;Repeat process for additional characters

.pS_Completed: ;Jumped to when completed writing a string of characters
ret ;Returns back to main "function"


Edit:
I apologize for the messy code, I guess GameDev doesn't support Assembly syntax highlighting. In any case, I think I may get a reply saying something about not having the DOS terminating character in the string. I tried with and without it, and it made no difference, and I think that since I'm using int 10h, it doesn't matter anyway.
Advertisement
That doesn't like a Unicode/ASCII problem, but rather a not null terminating your string problem. IIRC you can add the null terminator by using ,0 after your string. Ex:

testString db 'Hello world.', 0

That doesn't like a Unicode/ASCII problem, but rather a not null terminating your string problem. IIRC you can add the null terminator by using ,0 after your string. Ex:

testString db 'Hello world.', 0



You beat me to my edit. You were right though, I was trying to fix the problem with the dollar sign null terminating character for DOS, I didn't realize it was different using int 10h.

Edit:

One more question, when I used "test" instead of "testString" for defining the string, it came up with an error with "mov si, test"
error: invalid operand.

Also I didn't mention I was using FASM.

One more question, when I used "test" instead of "testString" for defining the string, it came up with an error with "mov si, test"


I believe "test" is the mnemonic for an instruction related to bitwise operations.

Edit: yes, a quick wiki indicates that "test" performs a bitwise AND on two operands and then sets some flag registers according to the result.
Ah, thank you. Hopefully my questions in the future won't be as stupid. I had a total Homer Simpson moment.

You beat me to my edit. You were right though, I was trying to fix the problem with the dollar sign null terminating character for DOS, I didn't realize it was different using int 10h.

int 10h with an AH of 0Eh prints a single character. It doesn't have any knowledge of strings at all. The problem is that the loop you wrote uses a null to detect the end of the string. That's what the cmp al, 0 is doing. If you don't put a null as part of your string it'll keep reading until it finds one, which is the garbage output you saw.

This topic is closed to new replies.

Advertisement