OSDev.org

The Place to Start for Operating System Developers
It is currently Sat May 04, 2024 5:18 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: General nasm question regarding pusha and my string function
PostPosted: Thu Nov 22, 2007 2:49 pm 
Offline
Member
Member

Joined: Wed Nov 14, 2007 3:19 pm
Posts: 65
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 :-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 8:23 pm 
Offline
Member
Member

Joined: Wed Nov 14, 2007 3:19 pm
Posts: 65
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. :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group