0

I have C Code that I am converting to arm assembly on a Raspberry Pi 3

How would I pass in a bmp image into a register to be used for reading, before branching into fopen of a file?

C Code that I am converting -

    char ifile[80] = "rainbow2.bmp";
    char ofile[80] = "rainbow_out.bmp";

    FILE *fpin, *fpout;

    fpin = fopen(ifile, "rb");
    fpout = fopen(ofile, "wb");

I was thinking something similar to this

    mov r0, ifile  @  r0 = rainbow2.bmp
    mov r1, rb     @  r1 = read ?
    bl fopen       @  fopen returns in r0/r1/fpin?
    mov r4, r0     @  r4 = fpin

    mov r0, ofile  @  r0 = output file rainbow_out.bmp
    mov r1, wb     @  r1 = write ?
    bl fopen       @  fopen returns *fp?
    mov r5, r0     @  r5 = fpout

I think the values ifile/ofile,rb/wb are wrong. I am unsure of what I need to pass into the registers for opening a bmp image in the same folder?

Chris
  • 15
  • 6
  • Have you run this thru a debugger to see what's in r0/r1 when you branch to fopen? – David Wohlferd May 23 '20 at 04:57
  • 3
    The fact that you're using `mov` looks suspicious. I would've expected to see something like `ldr r0,=ifile`. You need to show the declarations of `ifile` and those other strings. – Michael May 23 '20 at 06:53

1 Answers1

0

Found the solution.

    ldr r0, =inFile   @  r0 = rainbow2.bmp
    ldr r1, =rb       @  r1 = read
    bl fopen          @  fopen returns in r0/r1/fpin?
    mov r4, r0        @  r4 = fpin
Chris
  • 15
  • 6