ARMSim Assembly

um, I am not to sure to be honest. this is what i have so far. If you could pin point what i might be doing wrong, that'd be great.

     .equ SWI_Open,  0x66     ;Open  a file
     .equ SWI_Close, 0x68     ;Close a file
     .equ SWI_PrChr, 0x00   @ Write an ASCII char to Stdout

     .equ SWI_PrStr, 0x69     ;Write a null-ending string

     .equ SWI_RdStr, 0x6a     ;Read a string and terminate with null char
     .equ SWI_Exit,  0x11     ;Stop execution
        .equ Stdout,    1       @ Set output target to be Stdout

     .global   _start
     .text
    _start:

     ldr  r0, =InFileName     ;r0 points to the file name
     ldr  r1, =0              ;r1 = 0 specifies the file is input
     swi  SWI_Open            ;open the file ... r0 will be the file handle
     ldr  r1, =InFileHandle   ;r1 points to handle location
     str  r0, [r1]            ;store the file handle
     ldr  r0, =OutFileName    ;r0 points to the output file handle
     ldr  r1, =1
     swi  SWI_Open
     ldr  r1, =OutFileHandle
     str  r0, [r1]

read:
ldr r0, =InFileHandle ldr r0, [r0] ldr r1, =InString ldr r2, =80 swi SWI_RdStr ldr r0, =InString ;r0 points to the input string ldr r1, =OutString ;r1 points to the output string loop: ; ldrb r2, [r0], #1 ;get the next input byte ; then increment the input pointer b testZ cap: sub r2,r2,#32 ; subtract 32 to make it uppercase ascii testZ: cmp r2,#90 ;see if it is above ascii "Z" bgt cap testA: cmp r2,#65 ; see if it is above ascii "A" bgt store ; if it is > "A" and <="Z" it must be A-Z testch: cmp r2,#32 ;it is a space beq store testeof: cmp r2,#26 ;eof character - go to write beq write testeol: cmp r2,#0 ; eol character bne loop store: strb r2,[r1],#1 ; store the byte and inc pointer by 1 cmp r2,#0 ; if it's the end of the line fall through to write bne loop write:
ldr r0, =OutFileHandle ldr r0, [r0] ldr r1, =OutString swi SWI_PrStr ;write the null terminated string
ldr r1, =CRLF swi SWI_PrStr cmp r2,#0x1A bne read exit:
ldr r0, =InFileHandle ;r0 points to the input file handle ldr r0, [r0] ;r0 has the input file handle swi SWI_Close ;close the file ; ldr r0, =OutFileHandle ;r0 points to the output file handle ldr r0, [r0] ;r0 has the output file handle swi SWI_Close ;close the file ; swi SWI_Exit ;terminate the program .data

InFileHandle: .skip 4 ;4 byte field to hold the input file handle OutFileHandle: .skip 4 ;4 byte field to hold the output file handle ; InFileName: .asciz "input.txt" ;Input file name, null terminated InString: .skip 128 ;reserve a 128 byte string for input OutString: .skip 128 ;reserve a 128 byte string for output ; CRLF: .byte 13, 10, 0 ;CR LF ; OutFileName: .asciz "output.txt" ;Output file name, null terminated .end

/r/arm Thread Parent