I was watching about this values, then I find that there is not info about this????

Anyway, I do this little thing, hope you like it :).

By the way, ip and sp are not the values after the jump.... by the manipulation.

What I have noted is that sp have a value of 0xffec and I have pushed 9 words, mean 0xffec+18 => 0xffec+ 0x12 => 0xfffe I dont understand this, why not 0xffff.. by the way, I dont have a way to test it in real hardware.. :S.

Is only a bootsector.

call PushAll16
jmp start

retAddr_PushAll16 dw 0
pop word

push ss
push gs
push fs
push es
push ds
push cs

call $+3 ; push ip
push si
push di
push sp
push bp

push dx
push cx
push bx
push ax

push word

retAddr_PrintStackRegs dd 0
pop word
mov ah, 0x4
call PrintStr2CharVideo
inc si
call Space
pop ax
call Ax2Eax
mov , eax
push si
mov si, hexBuffer
mov ah, 0x09
call PrintStr2CharVideo
pop si
call Space
dec cx
jnz .again
push word

mov ax, 0xb800
mov es, ax
xor di, di

mov ax, 0x7c0
mov ds, ax

push bx
mov bx, 80*2
mul bl
mov di, ax
pop bx

mov byte, " "
inc di
inc di

mov al,
or al, al
jz .end
cmp al, 13
jnz .no13
add di, 80*2
inc si
jmp PrintStr2CharVideo
cmp al, 10
jnz .no10
push ax
push bx
mov ax, di
mov bx, 80*2
div bl
shr ax, 8
sub di, ax
inc si
pop bx
pop ax
jmp PrintStr2CharVideo
mov , ax
inc si
add di, 2
jmp PrintStr2CharVideo

push bx
mov bx, ax
and ax, 0xf0f0
and bx, 0x0f0f
shr ax, 4
bswap eax
mov ax, bx
mov bx, 4
cmp al,10
sbb al,69h
rol eax, 8
dec bx
jnz .again
rol eax, 8
xchg ah, al
bswap eax
pop bx

call InitCharVideo
call InitData

mov si, r1
mov ah, 0x05
call PrintStr2CharVideo

mov cx, 4
mov si, gr1
call PrintStackRegs

mov si, r2
mov ah, 0x05
call PrintStr2CharVideo

mov cx, 5
mov si, ir1
call PrintStackRegs

mov si, r3
mov ah, 0x05
call PrintStr2CharVideo

mov cx, 6
mov si, sr1
call PrintStackRegs

jmp $

hexBuffer times 4 db 0
db 0

r1 db "General Registers", 13, 10, 0
r2 db 13, 10, "Index and pointer Registers", 13, 10, 0
r3 db 13, 10, "Segment registers", 13, 10, 0

gr1 db "ax", 0
gr2 db "bx", 0
gr3 db "cx", 0
gr4 db "dx", 0

ir1 db "bp", 0
ir2 db "sp", 0
ir3 db "di", 0
ir4 db "si", 0
ir5 db "ip", 0

sr1 db "CS", 0
sr2 db "DS", 0
sr3 db "ES", 0
sr4 db "FS", 0
sr5 db "GS", 0
sr6 db "SS", 0

%assign here $-$$
%error HERE here

times 510 - ($-$$) db 0xFE
dw 0xAA55
times 1474560 - ($-second_sector) nop

Comments in those values?
Posted on 2005-05-02 22:50:15 by rea
The stack is top-down, so SP is incremented bytewise based on the size of the data being pushed, then the data is written. On a POP, the data is read and then SP is decremented in the same fashion. Pushing GS puts the stack at FFEE from FFEC, and each push does the same.

;Stack at 0000:FFEC
push ss ;Stack at 0000:FFEC
push gs ;Stack at 0000:FFEE
push fs ;Stack at 0000:FFF0
push es ;Stack at 0000:FFF2
push ds ;Stack at 0000:FFF4
push cs ;Stack at 0000:FFF6

call $+3 ;push ip, Stack at 0000:FFF8
push si ;Stack at 0000:FFFA
push di ;Stack at 0000:FFFC
push sp ;Stack at 0000:FFFE
Posted on 2005-05-03 20:26:45 by SpooK
Yes is top down, but SP is decremented by each push and incremented by each pop based on the size of data.

;Stack at 0000:FFFE
push ss ;Stack at 0000:FFEC
push gs ;Stack at 0000:FFFA
push fs ;Stack at 0000:FFF8
push es ;Stack at 0000:FFF6
push ds ;Stack at 0000:FFF4
push cs ;Stack at 0000:FFF2

call $+3 ;push ip, Stack at 0000:FFF0
push si ;Stack at 0000:FFEE
push di ;Stack at 0000:FFEC <--- This is the value pushed...
push sp ;Stack at 0000:FFEA

Now that you have write it, I see for what the stack top start (sp) is pointing at 0xFFFE is because is word aligned, if it was initialized to 0xFFFF it will be aligned to byte or other diferent than word or dword...

Correcting the values (sp and ip), the output is like this:

General Registers
ax AA55 bx 0000 cx 0001 dx 0000
Index and pointer Registers
bp 0000 sp FFFE di FFE4 si 009D ip 7C00
Segment registers
CS 0000 DS 0000 ES 0000 FS 0000 GS 0000

ax contain the signature of bootsector
cl the drive where boot
sp the stack top word aligned
di pointing somewhere in a "free" data area...???? no meaninfull value???? a result of a copy??.. si and di?
si point to a interrupt?? wich interrupt?
ip contain the next instruction to be executed and is where the bootsector is loaded CS:ip.
all the segments are initialized to zero or the start of memory.

Those values can be tacked like standar??
Posted on 2005-05-04 10:23:32 by rea
Yes, you are correct... that is what I get for posting when I am sleep deprived. What is worse is that I tried to solve a problem that wasn't even there :S

I tested the code in Bochs and had the same results. My best guess is that the bochs BIOS sets the stack default to the top of conventional memory.

On my computer, the BIOS defaults SP as 0000:03E4 (0x03D2 + 0x12), which is 4 bytes below the first 1000 bytes of memory.

If you are asking if these values can be treated like the standard, the answer is no, it is all up to the BIOS software.
Posted on 2005-05-04 14:27:36 by SpooK
mmm I see.

And the general registers, for example... a segment register for load 0. Perhaps not of much use... tought.

I think that
ax, cx, bp and the segments are standar??
Posted on 2005-05-04 15:17:15 by rea
you can't even depend on CS:IP being standard values upon entering bootsector code - you're only guaranteed that the code loads at 0x7C00 physically.
Posted on 2005-05-17 08:18:21 by f0dder