NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: yoran on September 02, 2018, 01:20:28 PM
-
Hey, so I have a file which I loaded 1d into. However when I load this into memory address 65532 and load 65532 into AL, it does not contain 1d (d means decimal, I loaded 1 into it).
Does anyone know how I can get 1 AS 1 into AL.
PS: I reboot after I write into the file.
-
You gave very little information. Are you using C's fopen, fread, fclose etc? Are u on windows or linux? 32-bit or 64-bit? What linker are you using?
-
Assuming you're on Win32, using C's file routines, and accessing a binary file, it could appear something like so... (I am too lazy to find out the exact parameters of fread(), but this should work);
;nasm -f win this.asm
;gcc -m32 this.obj -o this.exe
BITS 32
global _WinMain@16
extern _printf
extern _fopen
extern _fread
extern _fclose
section .bss
mybuff: resb 64
section .data
myfile: db 'myfile.bin',0 ;assume you have integer 1 in here as the first byte
mode: db 'r',0
fmt: db 'You get %d',0ah,0
section .text
_WinMain@16:
push ebp
mov ebp,esp
push mode
push myfile
call _fopen ;open for read
add esp,8
mov edi,eax ;save fd
push eax ;fd
push 10 ;read 10 bytes
push 64 ;buffer size
push mybuff ;copy to this buffer
call _fread
add esp,4*4
movzx eax,byte[mybuff] ;copy first byte to AL
push eax
push fmt
call _printf
add esp,8
push edi ;close fd
call _fclose
add esp,4
pop ebp
ret
;------- your binary file "myfile.asm" ---------
;------- nasm -f bin myfile.asm -o myfile.bin
;db 1d,3d
;
-
Oh, sorry. :)
I am using 16 bit NASM bare metal.
-
You need to show some code where you suspect is faulty.
-
Sorry for the late reply, but I don't know where it's faulty.. I put '1' into memory, write it, reboot, load and it doesnt work.
-
Then its all guesswork for the rest of us. I left 16-bit programming some time ago, but if you share some code, I am sure somebody on this board can help you identify the faulty part. Frank Kotler is good at 16-bit stuff ;)
-
Hi Guys,
Thanks for trying to help out, Stressful!
Yoran. what part of "show some code" do you not understand?
Gazing into my crystal ball and mumbling "it doesn't work" it mumbles back " you haven't got your segment registers in a row".
Best,
Frank
-
Judging from "65535", and "16-bit bare metal" clues, I suspect Yoran is doing read/write in High Memory Area as well. I'm not sure... forgot about those things already... when I was so eager to write my flat .COM bootloader :P