OSDev.org
https://forum.osdev.org/

General nasm question regarding pusha and my string function
https://forum.osdev.org/viewtopic.php?f=13&t=15476
Page 1 of 1

Author:  maverick777 [ Thu Nov 22, 2007 2:49 pm ]
Post subject:  General nasm question regarding pusha and my string function

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:
Code:
contents db  "Test ",0

mov ecx, axcontents;
call showstring;

showstring:
pusha;
mov al, byte [ecx]; al = first char

Now in the guys from the tutorial he has the same (much more code but heres the part I dont understand)
Code:
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)

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)
Code:
mov   bl, byte [edi]      ; get next character
cmp   bl, 0         ; is it 0 (Null terminator)?
je   .done         ; yep-bail out

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

Code:
   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 :-)

Author:  maverick777 [ Thu Nov 22, 2007 8:23 pm ]
Post subject: 

scrub this question as I studied exactly whch function were called after entry point right up until before my function, I even checked ones I thought wouldnt relate and Im quiety confident its because edi has been set to the base of video memmory. :-)

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/