You are on page 1of 4

ME445M:EmbeddedandRealTimeSystems

StudyguideSet#01

EE445M: EMBEDDED AND REAL TIME SYSTEMS StudyGuideSet#01

February15,2017

Course offered by the Department of Electrical


EngineeringatUniversityofTexasatAustin


Disclaimer:ThecontentsofthisdocumentisastudyguideforTheUniversityofTexasatAustin
EE445MSpring2017,EmbeddedandrealTimeSystems.

Reference:http://users.ece.utexas.edu/~valvano/arm

RTOS
Real Time Operating System

Note Taker: Hilgad Montelo (hilgad.montelo@utexas.edu)

CopyrightHilgadMontelo.Allrightsreserved.
ME445M:EmbeddedandRealTimeSystems
StudyguideSet#01

RTOSPreparation


1) Writeanassemblysubroutinethatselectsbit8.Theinputtothesubroutineisa32bitnumberinR0.The
outputinR0is0iftheinputbit8is0,andtheoutputis1iftheinputbit8is1.
Answer:

Mask8 AND R0,R0,#0x00000100 ;remove all bits except bit 8


LSR R0,R0,#8 ;move bit 8 into bit 0 position
BX LR

2) WriteCfunctionthatselectsbit8.Theinputtothefunctionisanunsigned32bitnumber.Theoutputofthe
functionis0iftheinputbit8is0,andtheoutputis1iftheinputbit8is1.
Answer:

unsigned long Mask8(unsigned long input)


{
unsigned long output;
output = input&0x00000100; // select bit 8
output = output>>8; // move bit 8 into bit 0 position
return output;
}

3) Howmanybitsareminimallyneededtorepresentalldaysinayear?WhatCdatatypeshouldbeusedto
storesuchvalues?
Answer:

Number of Bits = 9 bits


C Data Type = uint16_t or unsigned short

4) Forthefollowingoperationsequence,whatwillbethevalueofregisterR0andconditioncodebitsN,Z,V
andCafterexecutionofthesequence.Assumeallvaluesandregistersare8bitwide.
Answer:

CopyrightHilgadMontelo.Allrightsreserved.
ME445M:EmbeddedandRealTimeSystems
StudyguideSet#01


5) Considerthefollowingoperationsequence(inregular32bitARMassembly):

LDR R1,=-168
ASRS R2,R1,#2
CMP R1, R2
Markwhichofthefollowingbrancheswillbetakenafterexecutingtheabovesequence:
Answer:



6) Considerthefollowingassemblyprogram:
Answer:

AREA CODE ; Assume this starts at address 0x0000.1000


num DCD 0x87654321
Start LDR R0,=num
LDRSH R1,[R0]

WhatisthevalueinregisterR1attheendofexecution?
Answer:

The ARM can be configured to different endianness and the result


depends on that - default is little endian.

Big: 0xFFFF8765
Little: 0x00004321

7) GiventhefollowingARMassemblyprogram:
AREA DATA
0x20000000 00000000 res DCD 0
AREA CODE
0x000005D0 B500 f PUSH {LR}
0x000005D2 2801 CMP R0,#0x01
0x000005D4 D007 BEQ done
0x000005D6 B401 PUSH {R0}
0x000005D8 F1A00001 SUB R0, R0, #1
0x000005DC F7FFFFF8 BL f
0x000005E0 BC02 POP {R1}
0x000005E2 FB00F001 MUL R0, R0, R1
0x000005E6 F85DEB04 done POP {LR}
0x000005EA 4770 BX LR
0x000005EC F04F0002 Start MOV R0,#2
0x000005F0 F7FFFFEE BL f
0x000005F4 4900 LDR R1,=res
0x000005F6 6008 STR R0,[R1]

CopyrightHilgadMontelo.Allrightsreserved.
ME445M:EmbeddedandRealTimeSystems
StudyguideSet#01

AssumethestackpointerSPisinitializedto0x2001.0000.Showthecontentsofthestackandindicatethe
locationofthestackpointerrightafterthepointwhenthestatementataddressfhasjustbeenexecutedfor
thesecondtime.
Answer:

8) Writetheassemblycodetocreatea16bitsignedvariablecalledNum.Includethedetailsthatwillplacethe
variableinRAM.
Answer:

AREA data
Num SPACE 2

9) Considerthefollowing8bitaddition(assumeregistersare8bitswide,andassumetheconditioncodebits
aresetinawaysimilartotheCortexM4).Whataretheconditioncodebits?
Load 0x88 into R1
Load 0xC8 into R2
Adds R3 = R1+R2 ; setting the condition codes

Answer:

N Z V C
0 0 1 1

10) WriteasubroutineinCorassemblycalledSOS_DetectorthatfirstreadsPB7ninetimesveryquickly.Ifthe
nineconsecutiveinputsmatchthepattern"000111000",thenreturna1,otherwisereturna0.SOS_Detector
mustbeAAPCScompliant.
Answer:
SubroutineinC Subroutine inassembly
int32_t SOS_Detector(void) SOS_Detector
{ MOV R0,#0
uint32_t i,data=0; LDR R1,=GPIO_PORTB_DATA_R
for(i=0; i<9; i++){ MOV R2,#9
data = (data<<1)|( loop LDR R3,[R1] ; PORTB
GPIO_PORTB_DATA_R&0x80); AND R3,#0x80 ; PB7
} LSL R0,#1
if(data == (0x38<<7)){ ORR R0,R0,R3 ;combine bits
return 1; SUBS R2,#1
} BNE loop ;9 times
return 0; CMP R0,#(0x38<<7)
} BEQ yes
no MOV R0,#0
B done
yes MOV R0,#1
done BX LR

CopyrightHilgadMontelo.Allrightsreserved.

You might also like