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

Write an ARM assembly program that will generate 20 pseudo-random integers in th

ID: 3796643 • Letter: W

Question

Write an ARM assembly program that will generate 20 pseudo-random integers in the range 0 to 215-1 and store the numbers in 20 consecutive halfword locations beginning at address 0x40000000.  The following pseudocode will help you get started.

randomInteger   RN 0

pointer                 RN 1

counter                RN 2

randomInteger = any 32-bit seed value of your choosing;

pointer = 0x40000000;

counter = 20;

do {

randomInteger =(((randomInteger * 214013) + 2531011) >> 16) & 0x7FFF ;

store randomInteger in next available halfword location referenced by pointer;

adjust pointer;

--counter;

} while (counter != 0);

You will need to research the LSR, AND and STRH instructions, and indirect addressing.

Please comment as well

Explanation / Answer

; randomInteger = (((randomInteger * 214013) + 2531011) >> 16) & 0*7FFF;

ldr r1, =214013

ldr r2, =2531011

ldr r3, =randomInteger

ldr r0, [r3] ; load from randomInteger

mul r0, r1 ; *= 214013

adds r0, r2 ; += 2531011

lsrs r0, #16 ; >>= 16

ldr r2, =0*7FFF

ands r0, r2 ; &= 0*7FFF

str r0, [r3] ; store to randomInteger

;...............

; data part

randomInteger dcd 0*1234

SRAM_BASE EQU 0*40000000 ; static RAM location

AREA StrCopy,CODE,READONLY

ENTRY

LDR r1, =randomInteger ;source

LDR r0, =SRAM_BASE ;destination

MOV r3, #20 ;counter

LDR r4, =214013

LDR r5, =2531011

random

CMP r3, #0 ;check for zero termination

BLE out1 ;branch if no more out of loop

LDRH r2, [r1], #2 ;Load word from source, update address

MUL r6, r2, r1

MOV r2, r6

ADDS r2, r5

LSRS r2, #16

LDR r5, 0*7FFF

ANDS r2,r5

STRH r2, [r0], #2 ;write halfword to destination , update address

SUB r3, r3, #1 ;decrement counter

B random

out1

stop B stop

randomInteger DCW 0*1234 ;seed value

END

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote