×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ARM Assembly language...converting to lowercase and sorting!

ARM Assembly language...converting to lowercase and sorting!

ARM Assembly language...converting to lowercase and sorting!

(OP)
I have an assignment where I have to write a code that has 7 subroutines that perform the following:

· uart_init initializes the user UART for use.
· output_character transmits a character from the UART to HyperTerminal.
· read_string reads a string entered in HyperTerminal and stores it as a null-terminated string in memory. The user terminates the string by hitting Enter.
· output_string transmits a null-terminated string to be displayed in HyperTerminal.
· read_character reads a character which is received by the UART from HyperTerminal.
· convert_2_lowercase is the subroutine which converts all the characters in the string to lowercase.
· sort orders the characters in the word alphabetically.

CODE

AREA Serial, CODE, READONLY
EXPORT lab3

SER EQU 0x04           ; Serial Port
USTAT0 EQU 0x08   ; UART 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:", 0

ALIGN

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 r8, =string              ; Loads string into r8

MOV r9, r8
BL read_string


BL convert_2_lowercase

BL sort


;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------


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!,{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 contents of each byte
CMP r0, #13                            ; Finish when the Enter key is pressed
BNE STORE
MOV r0, #0
STRB r0, [r9]

LDMFD SP!, {lr}                           ; Restore register lr from stack
MOV pc, lr

;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------

read_character

STMFD SP!,{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!, {lr}                             ; Restore register lr from stack
MOV pc, lr

;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------

output_character

STMFD SP!,{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!, {lr}                                 ; Restore register lr from stack
MOV pc, lr

;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------

output_string                    ; SHOW STRING IN HYPERTERMINAL
                                            ; UNTIL IT REACH END

STMFD SP!,{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!, {lr}                       ; Restore register lr from stack
MOV pc, lr



;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------

convert_2_lowercase               ; CONVERTS VALUES ENTERED TO THEIR
                                                  ; LOWERCASE FORM

MOV r5, #65                          ; r5 holds ascii value for capital A
MOV r6, #90                          ; r6 holds ascii value for capital Z

LDR r11, string                      ; load address for string into r11
MOV r3, #0                              ; move #0 into r0

LOOPZ MOV r12, r11             ; move value in r11 to r12
LDRB r3, [r12]                         ; load byte content from r12 into r0

CMP r3, #13                   ; Compare contents of r3 to ascii value for SPACE
BEQ LOOP                     ; If equal to SPACE, Branch to LOOPE and increment

LOOPX CMP r3, r6                  ; Compare r0 to Z
BLE LOOPY                              ; Branch to LOOPY if r0 < Z
B DONE                                ; Otherwise, Branch to DONE

LOOPY CMP r3, r5                    ; Compare r0 to A
BLT DONE                                ; Branch to DONE if r0 < A

ADD r3, r3, #32                   ; Add 32 to acsii value in r3 and copy back to r3
LOOPE STRB r3, [r12], #1     ; store value in r3 into memory address r12 - Post
                                                    index by 1
CMP r12, #0                             ; Compare post indexed r12 address to NULL
BEQ output_string                 ; Branch to DONE if r12=0
B LOOPZ                                ; If unequal, unconditional branch to LOOPZ

DONE ; Done

;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------


STMFD SP!,{lr} ; Store register lr on stack

sort
LDR r7, =string
MOV r0, #0
LDRB r0, [r7]
MOV r8, r7

sort2
ADD r4, r7, r0
MOV r1, #0
ADD r8, r8, #1

after
LDRB r2, [r4], #-1
LDRB R3, [r4]
CMP r2, r3
BCC skip

STRB r2, [r4], #1
STRB r3, [r4]
ADD r1, r1, #1
SUB r4, r4, #1

skip
CMP r4, r8
BHI after
CMP r1, #0
BNE sort2

DONE3

LDMFD SP!, {lr} ; Restore register lr from stack
MOV pc, lr


;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------------

LDMFD SP!, {lr} ; Restore register lr from stack
MOV pc, lr
END

he code prompts the user fine, and it reads and transmits the string perfectly as well. However, I can't seem to figure out how to Branch and Link my program from the "main" part to my convert_2_lowercase and sort programs so that they function as well.

I appreciate any and all the help I can get. I'm honestly lost at this point.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close