• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Some weird character printing with int 10h

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Spirrwell  Members

Posted 01 July 2012 - 10:01 PM

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:

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.

### #2SiCrane  Moderators

Posted 01 July 2012 - 10:09 PM

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


### #3Spirrwell  Members

Posted 01 July 2012 - 10:15 PM

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.

Edited by Spirrwell, 01 July 2012 - 10:20 PM.

### #4Oberon_Command  Members

Posted 01 July 2012 - 10:26 PM

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.

Edited by Oberon_Command, 01 July 2012 - 10:27 PM.

### #5Spirrwell  Members

Posted 01 July 2012 - 10:37 PM

Ah, thank you. Hopefully my questions in the future won't be as stupid. I had a total Homer Simpson moment.

### #6SiCrane  Moderators

Posted 01 July 2012 - 10:48 PM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.