Page 1 of 1

Faulty print routine...

Posted: Sat May 10, 2014 11:06 am
by ThisMayWork
This print routine keeps failing on me and I can't figure out why... Usage:

Code: Select all

mov bx,MSG
call print_string
MSG: db "Hello",0

Code: Select all

print_string:
pusha
mov ah, 0x0E

print:
	mov al,[bx]
	cmp al, 0
	je done
	int 0x10
	add bx,1
	jmp print

done:
	popa
	ret

Re: Faulty print routine...

Posted: Sat May 10, 2014 11:22 am
by xenos
You cannot use BX here because int 0x10, AH = 0x0E interprets it as page number and color.

http://www.ctyme.com/intr/rb-0106.htm

SI and lodsb are your friends.

Re: Faulty print routine...

Posted: Sun May 11, 2014 2:22 am
by Combuster
Or trying to interpret "Hello" as instructions afterwards.

Re: Faulty print routine...

Posted: Sun May 11, 2014 2:40 am
by ThisMayWork
Combuster wrote:Or trying to interpret "Hello" as instructions afterwards.
Hmm, I have a jmp $ way before defining my data, so I don't think that would be a problem

Re: Faulty print routine...

Posted: Sun May 11, 2014 2:41 am
by ThisMayWork
XenOS wrote:You cannot use BX here because int 0x10, AH = 0x0E interprets it as page number and color.

http://www.ctyme.com/intr/rb-0106.htm

SI and lodsb are your friends.
Well, to be honest I was trying to comply with this: http://www.cs.bham.ac.uk/~exr/lectures/ ... os-dev.pdf
Section 3.4.8, Question 4.

Re: Faulty print routine...

Posted: Sun May 11, 2014 4:01 am
by Bender
ThisMayWork wrote:
XenOS wrote:You cannot use BX here because int 0x10, AH = 0x0E interprets it as page number and color.

http://www.ctyme.com/intr/rb-0106.htm

SI and lodsb are your friends.
Well, to be honest I was trying to comply with this: http://www.cs.bham.ac.uk/~exr/lectures/ ... os-dev.pdf
Section 3.4.8, Question 4.
Hint: XenOS talked about lodsb, check it out, and see what it does and how it can help you. Also, you may need to modify SI in your print routine if BX is the pointer to your string.
I haven't really read much of the document, but it doesn't use a cross-compiler which makes me feel suspicious, plus it's still seems to be under-construction, Section 6.3 - Section 7.2 are missing.

Re: Faulty print routine...

Posted: Sun May 11, 2014 5:48 am
by ThisMayWork
Bender wrote:
ThisMayWork wrote:
XenOS wrote:You cannot use BX here because int 0x10, AH = 0x0E interprets it as page number and color.

http://www.ctyme.com/intr/rb-0106.htm

SI and lodsb are your friends.
Well, to be honest I was trying to comply with this: http://www.cs.bham.ac.uk/~exr/lectures/ ... os-dev.pdf
Section 3.4.8, Question 4.
Hint: XenOS talked about lodsb, check it out, and see what it does and how it can help you. Also, you may need to modify SI in your print routine if BX is the pointer to your string.
I haven't really read much of the document, but it doesn't use a cross-compiler which makes me feel suspicious, plus it's still seems to be under-construction, Section 6.3 - Section 7.2 are missing.
I took a look at it, but now I need to find some other source of info. I chose this mainly because it doesn't use a cross-compiler (compiles with the -ffreestanding argument which I thought would produce the right executable) and also because it uses Intel Syntax ASM instead of GAS, which I find difficult to write. Does anybody have a proper book to recommend?