Page 1 of 1

push pop example for bootloaders

Posted: Tue Dec 22, 2015 12:07 pm
by 0b00000000

Code: Select all

bits 16
org 0x7c00

;
;Initialisation requires zeroing and setting some registers (SS, SP, CS, DS and ES)
;

jmp short $ + 2 ; or jmp short start ; or jmp short 0x7c02
start:
xor ax, ax              ; get ready to zero some registers
mov ss, ax              ; zero SS
mov sp, 0x7c00          ; set SP to beginning of stack
mov ds, ax              ; zero DS
mov es, ax              ; zero ES
jmp word 0x0000:next    ; zero CS

;
; Function will alter value of AX
;

next:
push ax
call do_something    ; function that changes DL
pop ax

...

times 510 - ($ - $$) db 0
dw 0xaa55

calls to sections of code and BIOS calls can change values of registers. Here's an example of how to do that. I'm sure others with more knowledge will be willing to point out which registers you should push and pop to make sure code doesn't behave as unintended.

Re: push pop example for bootloaders

Posted: Tue Dec 22, 2015 12:10 pm
by Techel
Ok. Whats the purpose of your post?