Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ARM ASSEMBLY LANGUAGE You are given some code in PA2-1.s that creates a string w

ID: 3919052 • Letter: A

Question

ARM ASSEMBLY LANGUAGE You are given some code in PA2-1.s that creates a string which should correspond to a four letter word. But, this string has its characters scrambled. You need to rearrange the characters so when you look at the string in memory it makes a word. The positions of the characters are numbered 0 through 3

The letter originally at position 0 should be moved to position 3

The letter originally at position 1 should be moved to position 0

The letter originally at position 3 should be moved to position 1

The letter at position 2 should not move

You will use a series of LDRB and STRB instructions with pre-indexed addressing to do these. Load each of the three letters to be moved into registers using LDRB instructions to get the letters from different positions. Then store them back to memory into the correct positions using STRB.

PA 2, problem 1 Your required header comments go here 4 Rearrange the characters in the string text in the following way: The letter originally at position e should be moved to position 3 The letter originally at position 1 should be moved to position ? The letter originally at position 3 should be moved to position 1 The letter at position 2 should not move 6 10 11 text 12 13 14 15 16 17 18 19 20 21 DCB Code begins here RO,-text Your code goes here L DR ; address of text now in Re L DRB L DRB LDRB L DRB RI, R2, R3, R4 , [RO, [R0 , [R0 , [R0 , #0] #1 #2] #3 23 24 25

Explanation / Answer

LDR and STR are the memory access instructions used in ARM assembly language.

Example:

LDR R0,[R1]

The value from the memory address of R1 is loaded into register R0.

STR R0,[R2]

The value of R0 is stored into memory address found in register R2.

There are following addressing modes used in LDR and STR (immediate -offset) instruction:

LDRB and STRB(Pre-indexed immediate)

whereas B stands for Byte(takes 8 bit data)

LDRB R0,[R1,#offset]

Data is loaded into a memory location R0 from the register, R1,then added to the given offset.

The range of immediate value is -4095 to +4095.

In above Program,'DESK' word is to be formed by following rearrangements:

The letter originally at position 0 'K' should be moved to position 3

The letter originally at position 1 'D' should be moved to position 0

The letter originally at position 3 'E' should be moved to position 1

Position 2 of the letter S will remain same.

Input :          K   D S E

Output:       D   E S K

The code that is to be written in immediate pre-indexed mode:

text DCB 'K','D','S','E'

LDR R0,=text

LDRB R1, [R0, #0]!
LDRB R2, [R0, #1]!
LDRB R3, [R0, #2]!
STRB R1, [R0, #0]!
STRB R2, [R0, #-3]!
STRB R3, [R0, #1]!

In immediate mode:

LDRB R1, [R0, #0]
LDRB R2, [R0, #1]
LDRB R3, [R0, #3]

STRB R1, [R0, #3]
STRB R2, [R0, #0]
STRB R3, [R0, #1]