Author Topic: Loading 1 byte from memory  (Read 6985 times)

Offline yoran

  • Jr. Member
  • *
  • Posts: 19
Loading 1 byte from memory
« 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.

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: Loading 1 byte from memory
« Reply #1 on: September 02, 2018, 05:01:38 PM »
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?

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: Loading 1 byte from memory
« Reply #2 on: September 02, 2018, 05:17:47 PM »
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);

Code: [Select]
;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
;

Offline yoran

  • Jr. Member
  • *
  • Posts: 19
Re: Loading 1 byte from memory
« Reply #3 on: September 02, 2018, 06:29:14 PM »
Oh, sorry. :)
I am using 16 bit NASM bare metal.

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: Loading 1 byte from memory
« Reply #4 on: September 02, 2018, 06:52:47 PM »
You need to show some code where you suspect is faulty.


Offline yoran

  • Jr. Member
  • *
  • Posts: 19
Re: Loading 1 byte from memory
« Reply #5 on: September 04, 2018, 08:14:40 AM »
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.

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: Loading 1 byte from memory
« Reply #6 on: September 04, 2018, 07:13:30 PM »
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  ;)

 

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Loading 1 byte from memory
« Reply #7 on: September 04, 2018, 07:45:27 PM »
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


Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: Loading 1 byte from memory
« Reply #8 on: September 04, 2018, 08:07:13 PM »
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