Reputation: 35
How can these 3 assembler directives cause a computer to reboot?
db 0x0ea
dw 0x0000
dw 0xffff
I found this from http://fisnikhasani.com/building-your-own-bootloader/
As far as my understanding goes, these 3 instructions send you to FFFF:0000
, the end of memory which causes a reboot by calling BIOS POST. But shouldn't there be a jmp
instruction in order to make that jump?
Also, it seems to me that in db 0x0ea
, ea is the machine instruction for jmp
. If so, how can db 0x0ea
write machine instruction? If db
and dw
have other functions apart from declaring variables, what are they? Can someone please point me to more literature surrounding db
and dw
and any of its hidden functions.
Upvotes: 2
Views: 889
Reputation: 61351
Think what does "declaring variables" mean in the context of assembly. db
and dw
, when a value is provided, write that value straight into memory. Code, on the other hand, is stored in the memory as, well, bytes. You can fill memory with bytes by having an assembler process your assembly source, or you can look up instruction encoding and fill memory with bytes by db/dw/dd commands.
That's what they're doing here. This sequence of bytes - ea 00 00 ff ff - encodes the jmp far 0ffffh:0
command.
Upvotes: 4
Reputation: 2534
You can hard-code instructions by simply inserting the proper bits using certain assembler directives (db
, dw
, etc...). In 16-bit mode, the bytes $EA0000FFFF
disassembles to:
ljmp $0xffff,$0x0
Which places the value $FFFF
in the CS
(code segment) register, and $0000
in the IP
(instruction pointer). This effectively starts executing code from the computer's reset vector, which should proceed to boot the system as if you just turned it on.
Upvotes: 1
Reputation: 41180
db
and dw
are not assembly instructions, they are pseudo instructions. Their arguments are simply used to initialize the byte or word allocated by the pseudo instruction. When they are used in a code segment, they can be used to create executable code.
Upvotes: 0