Faulty print routine...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Faulty print routine...

Post 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
"Programming is an art form that fights back."
-Kudzu
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Faulty print routine...

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Faulty print routine...

Post by Combuster »

Or trying to interpret "Hello" as instructions afterwards.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Re: Faulty print routine...

Post 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
"Programming is an art form that fights back."
-Kudzu
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Re: Faulty print routine...

Post 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.
"Programming is an art form that fights back."
-Kudzu
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

Re: Faulty print routine...

Post 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.
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Re: Faulty print routine...

Post 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?
"Programming is an art form that fights back."
-Kudzu
Post Reply