2014-10-05 09:11:03 +00:00
|
|
|
mov ah, 0x0e
|
|
|
|
|
|
|
|
; attempt 1
|
|
|
|
; Fails because it tries to print the memory address (i.e. pointer)
|
|
|
|
; not its actual contents
|
|
|
|
mov al, "1"
|
|
|
|
int 0x10
|
|
|
|
mov al, the_secret
|
|
|
|
int 0x10
|
|
|
|
|
|
|
|
; attempt 2
|
|
|
|
; It tries to print the memory address of 'the_secret' which is the correct approach.
|
2014-10-05 09:28:07 +00:00
|
|
|
; However, BIOS places our bootsector binary at address 0x7c00
|
2014-10-05 09:11:03 +00:00
|
|
|
; so we need to add that padding beforehand. We'll do that in attempt 3
|
|
|
|
mov al, "2"
|
|
|
|
int 0x10
|
|
|
|
mov al, [the_secret]
|
|
|
|
int 0x10
|
|
|
|
|
|
|
|
; attempt 3
|
|
|
|
; Add the BIOS starting offset 0x7c00 to the memory address of the X
|
2014-10-05 09:28:07 +00:00
|
|
|
; and then dereference the contents of that pointer.
|
|
|
|
; We need the help of a different register 'bx' because 'mov al, [ax]' is illegal.
|
|
|
|
; A register can't be used as source and destination for the same command.
|
2014-10-05 09:11:03 +00:00
|
|
|
mov al, "3"
|
|
|
|
int 0x10
|
|
|
|
mov bx, the_secret
|
|
|
|
add bx, 0x7c00
|
|
|
|
mov al, [bx]
|
|
|
|
int 0x10
|
|
|
|
|
|
|
|
; attempt 4
|
|
|
|
; We try a shortcut since we know that the X is stored at byte 0x2d in our binary
|
2014-10-05 09:28:07 +00:00
|
|
|
; That's smart but ineffective, we don't want to be recounting label offsets
|
|
|
|
; every time we change the code
|
2014-10-05 09:11:03 +00:00
|
|
|
mov al, "4"
|
|
|
|
int 0x10
|
|
|
|
mov al, [0x7c2d]
|
|
|
|
int 0x10
|
|
|
|
|
|
|
|
|
2014-10-05 09:28:07 +00:00
|
|
|
jmp $ ; infinite loop
|
2014-10-05 09:11:03 +00:00
|
|
|
|
|
|
|
the_secret:
|
2014-10-05 09:28:07 +00:00
|
|
|
; ASCII code 0x58 ('X') is stored just before the zero-padding.
|
|
|
|
; On this code that is at byte 0x2d (check it out using 'xdd file.bin')
|
2014-10-05 09:11:03 +00:00
|
|
|
db "X"
|
|
|
|
|
2014-10-05 09:28:07 +00:00
|
|
|
; zero padding and magic bios number
|
2014-10-05 09:11:03 +00:00
|
|
|
times 510-($-$$) db 0
|
|
|
|
dw 0xaa55
|