|
Prev: Testing memory cell by cell, and a specific cell ?
Next: Atomic operations in 32 and 64 bit platforms
From: NiTiN on 24 Jul 2008 06:06 Hi! I've got some really simple code that boots the system and displays a string. I've looked at a couple of examples and I'm aware of the load to 0x7c00. My jump references are fine but when I try to access variables, I get nulls instead of the actual data. Here's the source code: bits 16 org 0x7c00 jmp start helloMsg db 'A' start: mov al, [helloMsg] ;copy the A cmp al, 65 jne wrongChar call printChar ;print the A jmp end wrongChar: mov al, 66 ;print B if wrong character call printChar end: jmp $ printChar: mov ah, 0eh ;mov al, 65 mov bh, 0h mov bl, 7h int 10h ret ;510 bytes plus the 2 byte signature zero_padding: times 510 - ($ - $$) db 0 ;boot signature boot_sig: dw 0xaa55 The output I get on running this code is 'B' when it should be 'A'. I must be missing something. My setup is VMWare running on Windows, and an NASM compiler. Any help is appreciated. Regards, Nitin
From: Frank Kotler on 24 Jul 2008 08:19 NiTiN wrote: > Hi! > > I've got some really simple code that boots the system and displays a > string. I've looked at a couple of examples and I'm aware of the load > to 0x7c00. My jump references are fine but when I try to access > variables, I get nulls instead of the actual data. > > Here's the source code: > bits 16 > org 0x7c00 > > jmp start > > helloMsg db 'A' > > start: xor ax, ax mov ds, ax > mov al, [helloMsg] ;copy the A > cmp al, 65 > jne wrongChar > > call printChar ;print the A > jmp end > > wrongChar: > mov al, 66 ;print B if wrong character > call printChar > > end: > jmp $ > > printChar: > mov ah, 0eh > ;mov al, 65 > mov bh, 0h > mov bl, 7h > int 10h > ret > > ;510 bytes plus the 2 byte signature > zero_padding: times 510 - ($ - $$) db 0 > > ;boot signature > boot_sig: dw 0xaa55 > > > The output I get on running this code is 'B' when it should be 'A'. I > must be missing something. ASSume nothing, except that your code is loaded at 7C00h, and the boot drive is in dl. Might want to think about where your stack is, too... Best, Frank
From: Wolfgang Kern on 24 Jul 2008 09:22 "NiTiN" asked: > I've got some really simple code that boots the system and displays a > string. I've looked at a couple of examples and I'm aware of the load > to 0x7c00. My jump references are fine but when I try to access > variables, I get nulls instead of the actual data. I'd try a colon helloMsg: db 'A' __ wolfgang _________________________ > Here's the source code: > bits 16 > org 0x7c00 > > jmp start > > helloMsg db 'A' > > start: > mov al, [helloMsg] ;copy the A > cmp al, 65 > jne wrongChar > > call printChar ;print the A > jmp end > > wrongChar: > mov al, 66 ;print B if wrong character > call printChar > > end: > jmp $ > > printChar: > mov ah, 0eh > ;mov al, 65 > mov bh, 0h > mov bl, 7h > int 10h > ret > > ;510 bytes plus the 2 byte signature > zero_padding: times 510 - ($ - $$) db 0 > > ;boot signature > boot_sig: dw 0xaa55 > > > The output I get on running this code is 'B' when it should be 'A'. I > must be missing something. > > My setup is VMWare running on Windows, and an NASM compiler. > > Any help is appreciated. > > Regards, > Nitin
From: NiTiN on 24 Jul 2008 10:48 On Jul 24, 4:19 pm, Frank Kotler <fbkot...(a)verizon.net> wrote: -- SNIP -- > > . My jump references are fine but when I try to access > > variables, I get nulls instead of the actual data. > xor ax, ax > mov ds, ax > ASSume nothing, except that your code is loaded at 7C00h, and the boot > drive is in dl. Might want to think about where your stack is, too... > > Best, > Frank OMG, you were right!!! I set the ds, as you've suggested with a: mov ax, cs mov ds, ax ...and it worked!
From: NiTiN on 24 Jul 2008 10:55 On Jul 24, 5:22 pm, "Wolfgang Kern" <nowh...(a)never.at> wrote: > I'd try a colon > > helloMsg: db 'A' > __ > wolfgang Thanks for the suggestion. I still got the 0 instead of 65. I then tried setting 'ds', as Frank suggested and that worked for me. Thanks anyway! Just to share something that I read from the NASM documentation to figure out their syntax (I did some work with TASM about half a decade ago), it mentions that variable declarations and labels are treated the same in NASM and you can simply specify the variable name without using the 'offset' keyword.
|
Next
|
Last
Pages: 1 2 Prev: Testing memory cell by cell, and a specific cell ? Next: Atomic operations in 32 and 64 bit platforms |