push pop example for bootloaders

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Locked
0b00000000
Member
Member
Posts: 50
Joined: Sun Dec 20, 2015 4:00 pm
Libera.chat IRC: 0b00000000

push pop example for bootloaders

Post 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.
0x00
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: push pop example for bootloaders

Post by Techel »

Ok. Whats the purpose of your post?
Locked