General nasm question regarding pusha and my string function
Posted: Thu Nov 22, 2007 2:49 pm
Hi I have setup a small bootloader and have just got stage 3 working and the stack setup. Anyway the question isnt to do with OS dev, Im actually just trying to get better at asm , so I decided to write my own putstring function which just prints the contents of a string variable by looping through the characters,
I have a putstring fun ction that works great from a guide but im trying not to look at it to much but before the person does anything the do pusha
This makes sense to me as it stores all the registers on the stack, well exactly:
60 PUSHA 18 Push AX, CX, DX, BX, original SP, BP, SI, and
DI
Ok so heres the first part of mmy string function:
Now in the guys from the tutorial he has the same (much more code but heres the part I dont understand)
it then gets used
;first line it seems edi gets used as an index but I didnt think edi was assigned anywhere? (Im in protected mode btw so no ints)
Just to finally say I dont understand why edi points to the string start ? as this is how I set up my stack , yet the guys code from the guide works
2 final things, one regarding:
60 PUSHA 18 Push AX, CX, DX, BX, original SP, BP, SI, and
DI
what does it mean by ORIGINAL SP, BP, SI, and
DI
as in the most recent values I set sp bp etc to?
Also where can I find some nasm assembly tutorials using the same syntax thats on the brokenthorn site?(http://www.brokenthorn.com/Resources/OSDev8.html) and that also teach basic assembly but that doest use any shortcut code that relies on some form of os runtime
Thanks
I have a putstring fun ction that works great from a guide but im trying not to look at it to much but before the person does anything the do pusha
This makes sense to me as it stores all the registers on the stack, well exactly:
60 PUSHA 18 Push AX, CX, DX, BX, original SP, BP, SI, and
DI
Ok so heres the first part of mmy string function:
Code: Select all
contents db "Test ",0
mov ecx, axcontents;
call showstring;
showstring:
pusha;
mov al, byte [ecx]; al = first char
Code: Select all
showstring:
pusha;
mov al, byte [ecx]; al = first char
pop edi <-------I dont understand why pop edi? as I cant remember setting edi anywhere? (Only set the segments es, ds , sp etc when setting stack)
;first line it seems edi gets used as an index but I didnt think edi was assigned anywhere? (Im in protected mode btw so no ints)
Code: Select all
mov bl, byte [edi] ; get next character
cmp bl, 0 ; is it 0 (Null terminator)?
je .done ; yep-bail out
Code: Select all
mov ax, 0x10 ; set data segments to data selector (0x10)
mov ds, ax
mov ss, ax
mov es, ax
mov esp, 90000h ; stack begins from 90000h
2 final things, one regarding:
60 PUSHA 18 Push AX, CX, DX, BX, original SP, BP, SI, and
DI
what does it mean by ORIGINAL SP, BP, SI, and
DI
as in the most recent values I set sp bp etc to?
Also where can I find some nasm assembly tutorials using the same syntax thats on the brokenthorn site?(http://www.brokenthorn.com/Resources/OSDev8.html) and that also teach basic assembly but that doest use any shortcut code that relies on some form of os runtime
Thanks