os-tutorial icon indicating copy to clipboard operation
os-tutorial copied to clipboard

3 - jump opcode causes a problem

Open h-enes-simsek opened this issue 2 years ago • 0 comments

In lecture 3 there is a problem due to the different outputs of the jump instruction.

This is asm code

;
; A simple boot sector program that demonstrates addressing.
;

mov ah , 0x0e ; int 10/ ah = 0eh -> scrolling teletype BIOS routine

; First attempt
mov al , the_secret
int 0x10 ; Does this print an X? no

; Second attempt
mov al , [the_secret]
int 0x10 ; Does this print an X? no

; Third attempt
mov bx , the_secret
add bx , 0x7c00
mov al , [bx]
int 0x10 ; Does this print an X?

; Fourth attempt
mov al , [0x7c1e]
int 0x10 ; Does this print an X?

jmp $ ; Jump forever. 
the_secret :
  db "X"

; Padding and magic BIOS number.
times 510 -( $ - $$ ) db 0
dw 0xaa55

Binary output according to the book

b4 0 e b0 1e cd 10 a0 1e 00 cd 10 bb 1e 00 81 c3
00 7 c 8a 07 cd 10 a0 1e 7c cd 10 e9 fd ff 58 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
***
00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa

Binary output in my computer (Win10-NASM)

B4 0E B0 1D CD 10 A0 1D 00 CD 10 BB 1D 00 81 C3 
00 7C 8A 07 CD 10 A0 1E 7C CD 10 EB FE 58 00 00 
***
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA

First jump code: e9 fd ff Second jumo code: EB FE

So the address of the 'X' is different because of the jump opcode. But we added 0x1e hardcoded offset. And this leads that 'the fourth attempt is not working. I don't know what causes this but the compiler can choose different options of course. A little reminder could be added not to waste people's time.

h-enes-simsek avatar Dec 11 '22 16:12 h-enes-simsek