placing string into DS:SI
placing string into DS:SI
i'm trying to print a string in my boot loader, but its not working. I belive its that my string is not being loaded correctly into DS:SI. The function looks something like this:
lds si, [msg] ;mov si, [msg] dosn't work either
print:
lodsb
cmp al, 0
je done
mov ah, 0Eh
int 10h
jmp print
done:
blah blah blah debugging crap then
msg dw "MESSAGE", 0
the int instruction in the loop is never executed, and it jumps to done in the first time through the loop.
thanks,
Mr_Spam
lds si, [msg] ;mov si, [msg] dosn't work either
print:
lodsb
cmp al, 0
je done
mov ah, 0Eh
int 10h
jmp print
done:
blah blah blah debugging crap then
msg dw "MESSAGE", 0
the int instruction in the loop is never executed, and it jumps to done in the first time through the loop.
thanks,
Mr_Spam
Re:placing string into DS:SI
Try this
To call it, all you have to do is this:
Hope this helps!
Code: Select all
PrintMsg:
mov ah, 0x0E ; Teletype mode
mov bh, 0x00 ; Page number
.nextchar:
lodsb ; Load [si] into al and increment si
or al, al ; Set the Zero Flag if al = 0
jz .return ; If the Zero Flag isset, jumpto .return
int 0x10 ; Call BIOS video function
jmp .nextchar ; Loop around to write next character
.return:
ret ; Return
Code: Select all
mov si, bootmsg
call PrintMsg
Code: Select all
bootmsg db 'Its working", 13, 10, 0
Re:placing string into DS:SI
Previous post's code looks good, use that.
Just wanted to clear up what seems to be a fairly common gotcha in NASM syntax.
Here goes nothing.
This code sets vChar to be the memory offset to the data. Ie the label vChar is a pointer to the actual memory location of the data, not the value of the data.
This moves the value of the pointer into ax. I think a C example might be something like someVar=*vChar (My C isn't too good so that may be an incorrect example, but the meaning should be plain)
This moves the value of the byte (Because al is byte sized so the value is assumed byte sized) pointed to by vChar into register al. Once again, I think a C example would be simply someVar=vChar.
Don't mean to go on about it if this is something you already know, but it is essential in both C and ASM that people are comfortable with both the differences between pointers and values and how to handle them within their code.
Just wanted to clear up what seems to be a fairly common gotcha in NASM syntax.
Here goes nothing.
Code: Select all
vChar db 0x8h
Code: Select all
mov ax, vChar
Code: Select all
mov al, [vChar]
Don't mean to go on about it if this is something you already know, but it is essential in both C and ASM that people are comfortable with both the differences between pointers and values and how to handle them within their code.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:placing string into DS:SI
this assumes that strings is a segment:offset pointer, not an array of char to be displayed..bdjames wrote: 16 bit
lds si, [string]
32 bit
lea esi, [string]
Re:placing string into DS:SI
Its still not working :-\
heres what i have now:
mov si, msg
call displ
mov ax, 0E07h ;beep function
int 10 ;beep!
freez:
jmp freez
displ:
mov ah, 0Eh
mov bh, 0x0
.putch:
lodsb
or al, al
jz .done
int 10h
jmp .putch
.done:
ret
msg db "hello", 0
It beeps when its ran but it still dosn't display the string
for some reason i am most sceptical about the mov si, msg and the lodsb directives
heres what i have now:
mov si, msg
call displ
mov ax, 0E07h ;beep function
int 10 ;beep!
freez:
jmp freez
displ:
mov ah, 0Eh
mov bh, 0x0
.putch:
lodsb
or al, al
jz .done
int 10h
jmp .putch
.done:
ret
msg db "hello", 0
It beeps when its ran but it still dosn't display the string
for some reason i am most sceptical about the mov si, msg and the lodsb directives
Re:placing string into DS:SI
after some more debugging of that function, i have found that the lodsb command loads 0 into al on the first attempt and all attempts after. what series of commands would replace the functionality of the lodsb command?
Re:placing string into DS:SI
after even more and more hours of debugging, it has end up that even this simple code dosn't display crap, only moves the curser 1 char.
mov al, [msg]
mov ah, 0Eh
int 10h
freez: jmp freez
then...
msg db 61h ; letter a
???? what the h*ll? ??? ??? ???
this works:
mov al, 61h
mov ah, 0Eh
int 10h
freez: jmp freez
I am extreemly puzzeld. Through ours of debugging, al is always 0 because the contents of si is 0 after i mov si, msg in the original functions.
I am extreemly confused ??? ??? ??? ??? ???
any insight would be MUCH apreciated!!!
thanks,
Mr_Spam
mov al, [msg]
mov ah, 0Eh
int 10h
freez: jmp freez
then...
msg db 61h ; letter a
???? what the h*ll? ??? ??? ???
this works:
mov al, 61h
mov ah, 0Eh
int 10h
freez: jmp freez
I am extreemly puzzeld. Through ours of debugging, al is always 0 because the contents of si is 0 after i mov si, msg in the original functions.
I am extreemly confused ??? ??? ??? ??? ???
any insight would be MUCH apreciated!!!
thanks,
Mr_Spam
Re:placing string into DS:SI
Ok, I'll admit that I just do not see how this is difficult. Anyhow, here's some code.
Here's how you would declare a string.
Here's how to use it.
Note that DS had better be a relevant segment, the value you should set it to depends on wether or not you are using org. This is a common gotcha, expecially after the pmode switch.
Amazingly enough this should look almost exactly like the previous example by beyondsociety. There's only a few ways to print strings in BIOS efficiently.
Code: Select all
;**********************************************************************
;* Simple print function for 0 terminated strings using teletype mode *
;* Takes DS:SI as a pointer to the string being printed *
;**********************************************************************
BIOS_Print:
???push ax
???push bx
???mov ah, 0x0e
???mov bx, 0x0007
.1:
???lodsb
???or al, al
???jz short .2
???int 0x10
???jmp short .1
.2:
???pop bx
???pop ax
???retn
Code: Select all
vStr???db 'Hello World',13,10,0
Code: Select all
???mov si, vStr
???call near BIOS_Print
Amazingly enough this should look almost exactly like the previous example by beyondsociety. There's only a few ways to print strings in BIOS efficiently.
Re:placing string into DS:SI
new break through after more debugging:
if i put a string into the varriable after the program starts executing, it prints the string.
any one know why or how to fix it?
thanks,
BK
msg
if i put a string into the varriable after the program starts executing, it prints the string.
if i predeclare the varriable with the string it don't work.mov dword [msg], 'test'
mov si, msg
call displ
jmp $
displ:
mov ah, 0Eh
mov, bh, 0
.putch
lodsb
cmp al, 0
je .done
int 10h
jmp .putch
.done:
ret
msg db 0
any one know why or how to fix it?
thanks,
BK
msg
Re:placing string into DS:SI
BootSector Segment
Assume Cs:BootSector
Org 7C00h
Start:
mov ax,cs
mov ds,ax
mov bx,offset Boot_Message
mov cx,offset Boot_Message_delim - Boot_Message
Display_String:
mov al,byte ptr [bx]
inc bx
mov ah,0eh
push bx
mov bx,0007h
int 10h
pop bx
Loop Display_String
String_Done:
jmp String_Done
Boot_Message:
db "Hello World!",0
Boot_Message_delim:
BootSector ENDS
END Start
Assume Cs:BootSector
Org 7C00h
Start:
mov ax,cs
mov ds,ax
mov bx,offset Boot_Message
mov cx,offset Boot_Message_delim - Boot_Message
Display_String:
mov al,byte ptr [bx]
inc bx
mov ah,0eh
push bx
mov bx,0007h
int 10h
pop bx
Loop Display_String
String_Done:
jmp String_Done
Boot_Message:
db "Hello World!",0
Boot_Message_delim:
BootSector ENDS
END Start
Re:placing string into DS:SI
I think the previous poster is right. As it seems to me you have a problem in reading data from variables and not printing data. So I think you make a mistake in setting ds right. The best ting you can do is using org 0x7c00 and than copying cs to ds:
Be careful that your bootsector is smaller than 512 bytes. If a variable has the value 0 but you set it to a non-zero value it would be possible that you did something wrong in addressing this variable. (at system bootup the whole memory is set to zero).
I hope that helps you solving your problem.
Code: Select all
org 0x7c00
;Start of bootsector
Start:
mov ax, cs
mov ds, ax
; Now you should be able to access data
; ...
End:
;here you can put your data
I hope that helps you solving your problem.
Re:placing string into DS:SI
OMG IT WORKS NOW!!!!! THANK YOU SO MUCH!!!!!!!
the big differance,
mov ax, cs
mov ds, ax
THANK YOU!!!!!
ive beeen breating my brains out over this for days!! thank you sooo much!!
the big differance,
mov ax, cs
mov ds, ax
THANK YOU!!!!!
ive beeen breating my brains out over this for days!! thank you sooo much!!