1


I can't resolve my problem with memory mapping on the floppy when I try to access to it from assembly.
BTW, there are bare bones of my OS project.

main.asm:

start:
mov ax, 07C0h
mov ds, ax

mov ah, 02h
mov al, 1
mov ch, 0
mov cl, 2
mov dh, 0
mov bx, 0x0500
mov es, bx
xor bx, bx
int 0x13 ; read second sector

jmp 0x0500:0 ; Everything work good
times 510 - ($ - $$) db 0
db 0x55
db 0xAA

Everything work for now.

second.asm:
mov ax, 0x0500
mov ds, ax
xor si, si

mov ah, 0Eh
mov al, [msg]
int 0x10 ; It's work

jmp end ; Im avoid variable declaration because this stopping program (can you explain me why?)
msg db 'y'
end:

And now, in the third file, I'm trying to print another variable but it's printing random character.

third.asm:
mov ah, 0Eh
mov al, [msg2] ; This don't print my var
int 0x10

jmp $
msg2 db 'b'

Every file I'm recording to the floppy image and booting in qemu-system-i386 emulator for Linux.

y3v4d
  • 195
  • 14
  • 3
    How do you glue those file together? *Second.asm* works because you put it at the beginning of a segment and with no `ORG` directive the assembler (re)starts counting from 0 (segmentation and will act as a relocation here). If *third.asm* is assembled by itself and the resulting binary files joined, it won't work. Also, how do you get from *second.asm* to *third.asm*? i.e. what's the code after the `end` label? Note: You need to skip over variables because the CPU will interpret them as code, skewing all the subsequent instruction when decoding them. – Margaret Bloom Aug 29 '17 at 09:47
  • @MargaretBloom I'm recording all of this file in sequence with dd command. This means code after end of the second.asm is the start code of the third.asm. Interrupt in the third file works, but doesn't print my char. – y3v4d Aug 29 '17 at 09:52
  • 2
    It's better to let the assembler join the files together with the *include*-like directive. This way offset are computed correctly and you don't need to mess with a lot of `ORG`s – Margaret Bloom Aug 29 '17 at 09:55
  • @MargaretBloom Okey, thanks for help! – y3v4d Aug 29 '17 at 09:56
  • 2
    You are welcome. Beware that some `ORG` are necessary, depending on how you layout your source and where you put the binary in memory. Just be aware of how the assembler computes the offsets. – Margaret Bloom Aug 29 '17 at 10:00

0 Answers0