Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1: Write an ARM assembly language routine to count the number of 1s in a 32-bit word in ro and return the result in

image text in transcribed

Exercise 1: Write an ARM assembly language routine to count the number of 1s in a 32-bit word in ro and return the result in ri. code: OnesCount LDR ro, = 0x11AB003F MOV ri, #0x0 MOV r2, #32 MOVS ro, r0, ROR #1 ADDCS r1, r1, #1 SUBS r2, r2, #1 BNE OnesCount ; dummy value for rl (11 ones) ;clear ones counter ;use r2 as the loop counter Repeat: rotate ro right set flags ;if carry set increment ls counter idecrement loop counter ; until all bits tested If this was a subroutine Count, the code might be: ;set up dummy r2 area test, CODE, readwrite ADR sp, Stacki LDR r2,=0xFFFFFFFF STR r2, [sp] LDR ro, = OxFFAB123A BL Count MOV r3, rl NOP NOP ; dummy data ; call routine ; read result ;save r2 and return on the stack Count STMFD sp!, {r2, lr} MOV r1, #0x0 MOV r2, #4 OnesCount MOVS ro, r0, ROR #1 ADDCS ri, r1, #1 SUBS r2, r2, #1 BNE OnesCount LDMFD sp!, {r2, pc} ; restore r2 and return Stack Stacki DCD 0,0,0,0,0 DCD 0,0,0,0,0 Exercise 1: Write an ARM assembly language routine to count the number of 1s in a 32-bit word in ro and return the result in ri. code: OnesCount LDR ro, = 0x11AB003F MOV ri, #0x0 MOV r2, #32 MOVS ro, r0, ROR #1 ADDCS r1, r1, #1 SUBS r2, r2, #1 BNE OnesCount ; dummy value for rl (11 ones) ;clear ones counter ;use r2 as the loop counter Repeat: rotate ro right set flags ;if carry set increment ls counter idecrement loop counter ; until all bits tested If this was a subroutine Count, the code might be: ;set up dummy r2 area test, CODE, readwrite ADR sp, Stacki LDR r2,=0xFFFFFFFF STR r2, [sp] LDR ro, = OxFFAB123A BL Count MOV r3, rl NOP NOP ; dummy data ; call routine ; read result ;save r2 and return on the stack Count STMFD sp!, {r2, lr} MOV r1, #0x0 MOV r2, #4 OnesCount MOVS ro, r0, ROR #1 ADDCS ri, r1, #1 SUBS r2, r2, #1 BNE OnesCount LDMFD sp!, {r2, pc} ; restore r2 and return Stack Stacki DCD 0,0,0,0,0 DCD 0,0,0,0,0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions