I'm a green hand to assembly language. These days I used bochs to simulate the boot procedure from virtual floppy. But one thing I don't know is what the CS
register value is when the system initializes.
;; init registers
org 0x7c00
BaseOfStack equ 0x7c00
Label_Start:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, BaseOfStack
;; clear screen
mov ax, 0600h
mov bx, 0700h
mov cx, 0
mov dx, 0184h
int 10h
The above code is only part of it. When the ORG
command was executed, what was the CS
register value at the instruction mov ax, cs
. Is it the same as 0x7c00? Thanks.
Below is bochsrc configuration:
romimage: file="$BXSHARE/BIOS-bochs-latest"
vgaromimage: file="$BXSHARE/VGABIOS-lgpl-latest"
boot: floppy
floppy_bootsig_check: disabled=0
floppya: type=1_44, 1_44="myboot.img", status=inserted
pci: enabled=1, chipset=i440fx
vga: extension=vbe, update_freq=15
cpu: ips=15000000
log: bochsout.txt
mouse: enabled=0
megs: 32
push rbp instruction pushes the value of the register rbp onto the stack. Because it “pushes” onto the stack, now the value of rsp is the memory address of the new top of the stack.
For example, CL is the LSB of the counter register, whereas CH is its MSB. In total, this gives us five ways to access the accumulator, counter, data and base registers: 64-bit, 32-bit, 16-bit, 8-bit LSB, and 8-bit MSB.
I know that the %rax register is used to store a return value.
Zeroing a register depends. You can use xor reg, reg or sub reg, reg , but either of these sets the zero flag. There are times it makes sense to use mov reg, 0 when you want to set a register to zero without affecting the Z flag.
The specification says that CS:IP = 0000:7C00
at boot time, but some BIOS vendors boot off 07C0:0000
instead. The best way is to write your boot sector such that it works with both conventions by doing a far jump to a known selector early on:
org 0x7c00
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7c00
jmp 0x0000:set_cs
set_cs:
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With