Page 1 of 1
Writing string to screen using bios interrupts.
Posted: Sun Sep 22, 2013 4:34 am
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
Re: Writing string to screen using bios interrupts.
Posted: Sun Sep 22, 2013 4:55 am
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.
Re: Writing string to screen using bios interrupts.
Posted: Sun Sep 22, 2013 7:03 am
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?
Re: Writing string to screen using bios interrupts.
Posted: Sun Sep 22, 2013 7:44 am
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.
Re: Writing string to screen using bios interrupts.
Posted: Sun Sep 22, 2013 11:44 am
by Combuster
Noob error. The amount of bytes between the set directive and string2 is both strings.
Re: Writing string to screen using bios interrupts.
Posted: Sun Sep 22, 2013 12:57 pm
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