Writing string to screen using bios interrupts.

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
predator5047
Posts: 2
Joined: Sun Sep 22, 2013 4:26 am

Writing string to screen using bios interrupts.

Post by predator5047 »

I am trying to create my own bootloader and when I print str1 is prints it correctly but when i print str2 it prints both strings.But if swap the location of str1 and str2 in my file the reverse happens (it prints str2 correctly but when i print str1 it prints both strings).
Here is my code.

Code: Select all

.code16
.data
str2:
.ascii "This is the second string."
str1:
.ascii "This is the first string."

.set str1_len, .-str1 
.set str2_len, .-str2
.text
.globl _start

_start:
jmp $0x7C0, $_next

_next:
cli
movw %cs, %ax #setup segment registers
movw %ax, %ds 
movw %ax, %es 
sti

movw $str2, %bp 
movw $str2_len, %cx 
call print


jmp hang

print:
movw $0x1300, %ax # write string moving cursor
movb $0x0, %bh # page number
movb $0x1, %bl # color blue
xorw %dx, %dx # print in 0,0
int $0x10
ret

hang:
jmp hang

User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Writing string to screen using bios interrupts.

Post by bwat »

You haven't run this through a debugger, this much is obvious. Seriously, run it through a debugger, single step the code checking all the registers that are set up before the BIOS call, compare the register contents with the BIOS call specification, then come back and tell us what's wrong. I can see an obvious problem which would lead to the behaviour you're seeing (and I don't have all the BIOS calls details in my head, I look them up when I need to which isn't often).

If you don't have a debugger, then you're not really doing the programming thing. Learning to use a debugger effectively, or even writing your own as people used to do, is part and parcel of being a programmer.
Every universe of discourse has its logical structure --- S. K. Langer.
predator5047
Posts: 2
Joined: Sun Sep 22, 2013 4:26 am

Re: Writing string to screen using bios interrupts.

Post by predator5047 »

I run it through a debugger I think the problem is here

Code: Select all

0x7c0f:	mov    $0x28,%bp
0x7c12:	mov    $0x6,%cx
it should move the length of str2 is 2 not 6 why would it generate that?
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Writing string to screen using bios interrupts.

Post by bwat »

predator5047 wrote: it should move the length of str2 is 2 not 6 why would it generate that?
I don't understand that sentence --- it's not grammatically correct. If the length is wrong, then maybe you should look at how the length is calculated? Remember, the assembler will only generate the code you instruct it to. I think you've almost fixed your problem.
Every universe of discourse has its logical structure --- S. K. Langer.
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: Writing string to screen using bios interrupts.

Post by Combuster »

Noob error. The amount of bytes between the set directive and string2 is both strings.
"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 ]
AbstractYouShudNow
Member
Member
Posts: 92
Joined: Tue Aug 14, 2012 8:51 am

Re: Writing string to screen using bios interrupts.

Post by AbstractYouShudNow »

A simple length error, as everyone found...
But you should have a function for printing strings that would print each single character until a zero is found, and use .asciz instead of .ascii
Post Reply