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.
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.