0

It seems that I may be here a lot over the next couple days... :)

My code is as follows and works for BOCHS x86 emulator

-- BOOT.ASM --
[org 0x7c00]

mov dx, 0x7c00
call printhex
mov bx, printthistoo
call printaddr
jmp $

%include "print.asm"

printthis:
    db 'Letters!', 0
printthistoo:
    db ' Yes, all of these!', 0

times 510-($-$$) db 0

dw 0xaa55

-- PRINT.ASM --
printaddr:
    pusha
    mov ah, 0x0e
    lp:
    mov al, [bx]
    cmp al, 0
    jne printch
    jmp doneaddr
    printch:
    int 0x10
    add bx, 1
    jmp lp
    doneaddr:
    popa
    ret

printhex:
    mov cx, 0x3
    mov ax, 0xF
    lph:
    mov bx, 0x0
    add bx, ax
    and bx, dx
    cmp bx, ax
    je log
    sub ax, 0x1
    jmp lph
    log:
    cmp ax, 0x9
    jle lognum
    jmp loglet
    finlog:
    cmp cx, 0x0
    je printnd
    mov ax, 0xF
    sub cx, 0x1
    shr dx, 4
    jmp lph
    lognum:
    mov bx, extemplate
    add bx, cx
    add bx, 0x2
    add ax, 48
    mov [bx], al
    jmp finlog
    loglet:
    mov bx, extemplate
    add bx, cx
    add bx, 0x2
    add ax, 0x7
    add ax, 48
    mov [bx], al
    jmp finlog
    printnd:
    mov bx, extemplate
    call printaddr
    ret

extemplate:
    db '0x0000', 0

After a couple of tries with BOCHS, I decided to try the code on my physical computer. I loaded the code onto a USB stick with RUFUS and booted it. However, all that happened was a cursor freaking out and then a spade character printing onto the screen. Can anyone tell me what I did wrong?

Jester
  • 56,577
  • 4
  • 81
  • 125
Kyle G
  • 35
  • 1
  • 6
  • 2
    As usual, you forgot to set up `DS`. – Jester Oct 27 '16 at 22:54
  • @Jester Yeah, that worked. Pardon my lack of knowledge, I had simply thought the `[org 0x7c00]` would work the same way. – Kyle G Oct 27 '16 at 23:14
  • 4
    The `org` tells the assembler to assume that offset, but due to real mode addressing your code might end up in segment `7c0h` at offset `0` instead, which nevertheless maps to the same physical address. – Jester Oct 27 '16 at 23:41

0 Answers0