I have written the following code for reading ad outputting characters and strings and then converting it to lowercase and sorting it through bubble sort. It seems to read and output properly but not convert to lowercase and sort the string typed in the Hyper terminal via the UART. Can someone please help me as to what I am doing wrong? I have a strong feeling it has something to do with my registers and some part of the lowercase code but I am not sure!! Please Help...Thank you. I have attached the code for reference. Code: AREA Serial, CODE, READONLY EXPORT lab3 SER EQU 0x04 ; Serial Port USTAT0 EQU 0x08 ; UART0 Status Register TRANS EQU 0x0C ; Transmit Register RECEIV EQU 0x10 ; Receive Register BAUD EQU 0x14 ; string = "--------------------",0 prompt = "Enter a string up to 20 characters long, then press Enter: ", 0 ALIGN ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- uart_init ; INITIALIZE UART STMFD SP!,{lr} ; Store register lr on stack LDR r1, =0x03FFD000 ; Load base address into r1 MOV r2, #0 ; Turn off serial port STR r2, [r1, #SER] ; Contents of 0x3FFD004, stored into r2 LDR r1, =0x03FFD000 ; Load base address into r1 MOV r2, #3 ; Set port for 8 bits, 1 stop, 0 parity STR r2, [r1] ; Store the value 3 into memory address 0x3FFD000 LDR r1, =0x03FFD000 ; Load base address into r1 MOV r2, #9 ; Turn on serial port STR r2, [r1, #SER] ; Store the value 9 into memory address 0x3FFD004 LDR r1, =0x03FFD000 ; Load base address into r1 MOV r2, #162 ; Set to 9600 baud MOV r2, r2, LSL #4 ; Left shift value 162 stored in r2 by ; 4 spots, and recopy into r2 STR r2, [r1, #BAUD] ; Store left shifted value in r2 into ; memory address 0x3FFD014 LDMFD SP!, {lr} ; Restore register lr from stack MOV pc, lr ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- read_string ; READ STRING ENTERED BY USER UNTIL ; ENTER KEY IS REACHED STMFD SP!,{r1-r12, lr} ; Store register lr on stack STORE BL read_character STRB r0, [r9] ; Store the byte ADD r9, r9, #1 BL output_character ;Display the character CMP r0, #13 ; Finish when the Enter key is pressed BNE STORE LDMFD SP!, {r1-r12, lr} ; Restore register lr from stack MOV pc, lr ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- read_character STMFD SP!, {r1-r12,lr} ; Store register lr on stack LOOP LDR r1, =0x03FFD000 LDR r2, [r1, #USTAT0] TST r2, #32 BEQ LOOP LDR r0, [r1, #RECEIV] LDMFD SP!, {r1-r12,lr} ; Restore register lr from stack MOV pc, lr ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- output_character STMFD SP!,{r1-r12, lr} ; Store register lr on stack LOOP2 LDR r1, =0x03FFD000 ; Load memory address 0x03FFD000 into r1 LDR r2, [r1, #USTAT0] ; Load 0x03FFD004 into r2 TST r2, #64 ; Clear bit 6 BEQ LOOP2 STR r0, [r1, #TRANS] ; Store contents of 0x03FFD004 into r1 LDMFD SP!, {r1-r12, lr} ; Restore register lr from stack MOV pc, lr ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- output_string ; SHOW STRING IN HYPERTERMINAL ; UNTIL IT REACH END STMFD SP!,{r1-r12, lr} ; Store register lr on stack DISPLAY LDRB r0, [r10], #1 ; Load the byte from address in r10 into r0 ; and post-index r10 by 1 CMP r0, #0 ; Finish when the string comes to a 0 BEQ DONE2 BL output_character B DISPLAY DONE2 ; Branch here if null character is reached LDMFD SP!, {r1-r12, lr} ; Restore register lr from stack MOV pc, lr ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- convert_2_lowercase STMFD SP!,{r1-r12, lr} ; Store register lr on stack MOV r5, #65 ; r5 holds ascii value for capital A MOV r6, #90 ; r6 holds ascii value for capital Z LOOPZ CMP r0, #13 ; Compare contents of r3 to ascii value for ENTER BEQ DONE ; If equal to SPACE, Branch to LOOPE and immediately increment LOOPX CMP r0, r6 ; Compare r0 to Z BLE LOOPY ; Branch to LOOPY if r0 < Z B DONE ; Otherwise, Branch to DONE LOOPY CMP r0, r5 ; Compare r0 to A BLT DONE ; Branch to DONE if r0 < A LOOPE ADD r0, r0, #31 ; Add 32 to acsii value in r3 and copy back to r3 STRB r0, [r0], #1 ; store value in r3 into memory address r0 CMP r0, #0 ; Compare post indexed r12 address to NULL BEQ DONE ; Branch to DONE if r12=0 B LOOPZ ; If unequal, unconditional branch to LOOPZ DONE ; Done LDMFD SP!, {r1-r12, lr} ; Restore register lr from stack MOV pc, lr ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- SORT STMFD SP!,{lr} ; Store register lr on stack SORT2 LDR r8, =string COUNTER LDRB r12, [r8], #1 CMP r12, #0 BNE INCR B SORT1 INCR MOV r6, #0 ADD r6, r6, #1 B COUNTER SORT1 LDRB r1, [r8] LDRB r2, [r8, #1] CMP r1, r2 BLT DONEX CHANGE STRB r2, [r8] STRB r1, [r8, #1] DONEX ADD r8, r8, #1 CMP r2, #0 BEQ NEXT B SORT1 NEXT SUB r6, r6, #1 CMP r6, #0 BEQ DONE5 LDR r8, =string B SORT1 DONE5 LDMFD SP!, {lr} ; Restore register lr from stack MOV pc, lr ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- ;--------------------------------------------------------------------- lab3 STMFD SP!,{lr} ; Store register lr on stack BL uart_init ; Branch to uart_init LDR r10, =prompt ; Prompts user BL output_string LDR r9, =string ; Loads string into r9 BL read_string ; --------------------------------------------------------------------------------------------------------- BL convert_2_lowercase LDR r10, =string BL output_string BL SORT LDR r10, =string BL output_string LDMFD SP!,{lr} MOV pc, lr END
Are you sure about that? The code you claim to have written is virtually identical to the code that "Armnewbie87" insists he wrote in the following thread: http://www.go4expert.com/showthread.php?t=16305 So which of you is lying?
Hey, No one is lying...He is my partner in the same class! I didnt knew he has posted it here too! Thats we have the same code! Hope it' ok...his question is the same as me..we are unable to figure out how to link it together!