#;3/1/2009 RGD #;assemble: as -o toupper.o toupper.S #;link: ld -s -o toupper toupper.o #;Using GNU LD and GNU AS #;basic Example 1 on Openrisc stuff a delay slot #;NOTE or32 comments are just a '#' #;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;# #;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;# #;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;# .data testgreeting: .string "Convert string to upper case use delay slots:\n" glen = . - testgreeting lowercase: .string "test\n" len = .- lowercase .text .global _start .type _start,@function _start: l.addi r3, r0, 0x1 #; stdfile no 1 l.movhi r4, hi(testgreeting) #; move upper 16 in l.ori r4, r4, lo(testgreeting)#; or in the lower 16 l.addi r5, r0, glen #; strnlen l.addi r11, r0, 0x4 #; write sys call 4 l.sys 0x1 #; call os print initial l.addi r3, r0, 0x1 #; stdfile no 1 l.movhi r4, hi(lowercase) #; move upper 16 in l.ori r4, r4, lo(lowercase) #; or in the lower 16 l.addi r5, r0, len #; strnlen l.addi r11, r0, 0x4 #; write sys call 4 l.sys 0x1 #; call os print initial l.movhi r4, hi(lowercase) #; move upper 16 in l.ori r4, r4, lo(lowercase) #; or in the lower 16 l.jal to_upper #; j & l to function l.addi r3, r0, 0x1 #; stdfile no 1 l.addi r5, r0, len #; strnlen l.addi r11, r0, 0x4 #; write sys call 4 l.sys 0x1 #; print upper l.j local_exit #; all done l.addi r11, r0, 0x1 #; sys call use delay slot(exit) .global to_upper .type to_upper,@function to_upper: l.or r13, r4, r4 #; preserve r4 l.lbz r15, 0(r4) #; load first character top_of_loop: #; loop on string l.sflesi r15, 0x60 #; ascii char check low l.bf range_exit #; exit due to range l.nop 0x0 l.sfgesi r15, 0x7b #; ascii char check high l.bf range_exit #; exit due to range l.nop 0x0 l.addi r15, r15, -0x20 #; make it upper l.sb 0(r4), r15 #; write it out to mem l.addi r4, r4, 1 #; move up the string l.j top_of_loop #; spin it l.lbz r15, 0(r4) #; load next char use delay slot range_exit: l.jr r9 #; jump to link reg l.or r4, r13, r13 #; restore .global local_exit .type local_exit,@function local_exit: l.sys 1 #; call os call val in delay #;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;# #;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;# #;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#