Home

The ARMSim# User Guide - conneX

image

Contents

1. bal CKBLUELOOP TWO mov r0 45 clear sui SWI_CLEAR_LINE mov ri 0 mov r0 2 BL Display8Segment bal CKBLUELOOP THREE mov r0 45 clear sui SWI CLEAR LINE mov r1 0 mov x0 3 BL Display8Segment bal CKBLUELOOP FOUR mov r0 45 clear sui SWI CLEAR LINE mov r1 0 mov r 4 BL Display8Segment bal CKBLUELOOP FIVE mov r0 5 clear sui SNI CLEAR LINE mov r1 0 mov r 5 BL Display8Segment bal CKBLUELOOP SIX mov r0 5 clear sui SWI_CLEAR_LINE mov xl 0 mov x0 6 BL Display8Segment bal CKBLUELOOP SEVEN mov r 45 clear sui SWI CLEAR LINE mov r1 0 mov r0 7 BL Display8Segment bal CKBLUELOOP EIGHT mov r 45 clear sui SWI_CLEAR_LINE mov ri 0 mov r 8 BL Display8Segment bal CKBLUELOOP previous previous previous previous previous previous previous line line line line line line line 38 ARMSim User Guide NINE mov 0 45 clear previous line swi SWI CLEAR LINE mov r1 0 mov x0 9 BL Display8Segment bal CKBLUELOOP TEN mov 0 45 clear pr
2. mov RO Stdout print an initial message ldr R Messagel load address of Messagel label svi SWI PrStr display message to Stdout Open an input file for reading if problems print message to Stdout and exit ldr r0 InFileName set Name for input file mov r1 0 mode is input swi SWI Open open file for input bos InFileError Check Carry Bit C if 1 then ERROR Save the file handle in memory ldr r1 1InputFileHandle 1f OK load input file handle str r0 rl save the file handle Read integers until end of fil RLoop ldr r0 InputFileHandle load input file handle 1 r0 r0 swi SWI_RdInt read the integer into RO bos EofReached Check Carry Bit C if 1 then EOF reached print the integer to Stdout mov r1 r0 RI integer to print mov R Stdout target is Stdout swi SWI Print mov RO Stdout print new line ldr rl NI sui SWI PrStr bal RLoop keep reading till end of file End of fil EofReached mov RO Stdout print last message ldr RI EndOfFileMsg sui SWI PrStr Close a fil ldr RO InFileHandle get address of file handle ldr RO RO get value at address swi SWI_Close Exit swiSW1 Exit stop executing InFileError mov R Stdout ldr RI FileOpenInpErrMsg sui SWI PrStr bal Exit give up go to end data align InFileHandle skip 4 InFileNa
3. mov r 4 column number mov rl 2 row number ldr r2 RightLED pointer to string sui SWI_DRAW_STRING draw to the LCD screen Wait for 3 second ldr r3 3000 BL Wait turn on both led mov r0 LEFT_LED RIGHT_LED svi SWI SETLED clear previous line 2 mov r0 2 swi SWI CLEAR LINE draw a message to inform user to press a black button mov r0 6 column number mov rl 2 row number ldr r2 PressBlackL pointer to string sui SWI_DRAW_STRING draw to the LCD screen wait for user to press a black button mov r0 0 LB1 swi SWI_CheckBlack get button press into RO cmp 4x0 0 beq LBI if zero no button pressed cmp r0 RIGHT_BLACK_BUTTON bne LD1 ldr r0 SEG_B SEG_C SEG_F right button show swi SWI SETSEG8 mov r0 RIGHT LED turn on right led swi SWI SETLED bal NextButtons LD left black pressed ldr r0 SEG GISEG E SEG F display on 8segment swi SWI SETSEG8 mov r0 LEFT LED turn on LEFT led swi SWI SETLED NextButtons Wait for 3 second ldr r3 3000 BL Wait Test the blue buttons 0 9 with prompting then display number on 8 segment for 3 seconds If 59 invalid Draw a message to inform user to press a blue button mov r0 2 clear previous line 2 swi SWI CLEAR LINE mov r0 6 column number mov rl 2 row numbe
4. To run the program displayed in the Code View select Debug gt Run or click the Continue button on the toolbar see Table 1 The program runs until the simulator encounters a breakpoint see section 5 5 for an explanation of breakpoints or an SWI 0x11 instruction to exit the execution or a fatal error 4 4 Stopping a Program To stop a program that is currently running select Debug gt Stop or click the Stop button on the toolbar see Table 1 When the program has stopped any storage locations in the Register Cache and Memory Views that have been written to since the program started running are highlighted 4 5 Code View The Code View displays the assembly language instructions of the program that is currently active Next to each instruction the simulator shows the memory address of the instruction and the binary rep resentation of the instruction separated by a colon and displayed in hexadecimal format see Figure 2 Mah ss tarts With o JTUKU1000 E3A 1D4E ri STRING r2 SUBSTRING 00001014 EF000011 SearchString 00001018 E92D403E stmfid r131 r1 r5 r14 3E3E00000 Te address of an instruction 1 displayed in hexadecimal form 00001024 E5D14000 ri r 00001028 3540000 r4 0x00 0000102C Ai has ada 0000103 e binary representation of an instruction 00001034 FT displayed in hexadecimal form 00001038 E1401002 mv 7 0000103 000088 b
5. End of assembler errors FF watchview S memoryviewo Figure 9 Error Message 15 ARMSim User Guide Stackview 000053B0 00000000 000053B4 00000000 000053B8 00000000 000053BC 00000000 000053C0 00001240 000053C4 00001246 000053C8 00000000 000053CC 00000048 000053D0 000053F0 000053D4 000010aC 000053D8 00001240 000053DC 00001246 000053E0 00001240 000053E4 00001246 000053E8 00000000 000053EC 00000000 000053F0 00000000 000053F4 00001010 000053FC Top of the Stack Figure 10 Stack View 0000540C 00000000 Memory Address 6 5 Cache Views The Cache Views display the contents of the L1 cache The cache can have different organizations The one used by ARMSim can be selected by the user before an ARM program is executed The cache can consist of either a unified data and instruction cache displayed in the Unified Cache View or separate data and instruction caches displayed in the Data and Instruction Cache Views respectively depend ing on the cache properties selected by the user To set the cache properties select File gt Preferences and click the Cache tab Then use either the Cache Preferences Form see Figure 11 or the Cache Wizard to change the current cache settings and click OK To restore the default cache properties select the Restore Defaults button on the Cache Preferences Form Wh
6. end ARMSim User Guide 10 6 swiSWI_EXITExample Using the SWI Instructions for a Plug In Embest Board View Demonstration of Assume the H r H r Embest S3CE40 development board view EOU declaration from previous examples Clear the board clear the LCD screen swi SWI CLEAR DISPLAY Both LEDs off mov x0 0 svi SWI SETLED 8 segment blank mov x0 0 swi SWI_SETSEG8 draw a message to the lcd screen on linefFl mov r 4 column number mov rl 1 row number ldr r2 Welcome pointer to str swi SWI DRAW STRING draw to th ing display the letter H in Tsegment display ldr r0 SEG_B SEG_C SEG_G SEG_E S EG F sui SWI SETSEG8 turn on LEFT led and turn off RIGHT mov r0 LEFT LED swi SWI SETLED draw a message to the lcd screen on line 2 mov r 4 column number mov rl 2 row number ldr r2 LeftLED pointer to str Wait for 3 second ldr r3 3000 BL Wait turn on RIGHT led and turn off LEFT mov r0 RIGHT LED swi SWI SETLED draw a message to the lcd screen on line 2 led ing sui SWI DRAW STRING draw to the LCD screen led e LCD screen 35 ARMSim User Guide
7. A SEG G SEG F SEG C SEG D 85 word SEG A SEG G SEG F SEG E SEG D SEG C 86 41 ARMSim User Guide word SEG_A SEG_B SEG_C 7 word SEG_A SEG_B SEG_C SEG_D SEG_E SEG_F SEG_G 88 word SEG_A SEG_B SEG_F SEG_G SEG_C 9 word 0 Blank display PressBlue asciz Press a BLUE button 0 9 only 15 tests InvBlue asciz Invalid blue button try again TestBlue asciz Tests end 42
8. ARM object files generated by the Gnu tools provided with Cygwin or CodeSourcery ARM assembly source files can be created using any text editor e g TextPad and must be saved with a s filename extension ARM object files can be generated from ARM assembly files or C source files and must be compiled according to the instructions in the accompanying document on C and ARM For details on ARM assembly programming consult the references 4 2 Opening and Loading a File To open a file select File gt Load Then navigate to the folder in which the file is stored and double click the file to be opened When a file is opened it is automatically assembled if it is a source file and linked If the assembly and linking processes are successful the contents of the file appear in the Code View with the first instruction in the _start or main subroutine highlighted If the contents of the file appear in the Code View but the first instruction is not highlighted one must check the Output View for compiler errors see section 6 3 Notes file to be opened must be a source s file or an object o file If the file to be opened does not appear in the directory listing in the dialog box check to make sure that the appropriate file type has been selected ARMSim User Guide source code cannot be edited in the Code View window but must be changed in the original text editor and then reloaded 4 3 Running a Program
9. F Cache F Enabled Cache Size Associativity Replacement Strategy Cache Size Bytes Block Size Bytes Number of Blocks Fully Associative 1 Set Blocks Per Set C Random 256 R 16 1 16 1 0 1 2 Round Robin Direct Mepped Write Policy Allocate Policy Write Through C Read Allocate c C Write Back Write Allocate Both Restore Defouks Cache Wizard Cancel OK Figure 11 Cache Preferences Form 17 ARMSim User Guide In the Cache Views the boundaries of sets are marked by the blue square brackets along the left hand side of the view see Figure 12 Each row consists of a memory address followed by a cache block that shows the contents of the block at this address in memory When an instruction is executed using one of the step commands see section 5 1 or when a sequence of instructions is executed using the Debug gt Run option or the Continue button see section 4 3 any cache blocks that were written to during the execution of the instruction s are highlighted after the exe cution of the instruction s has finished When the Write Policy is set to Write Back a dirty block is marked by a red dot to the left of the row To clear all of the cache blocks select Cache gt Reset Resetting the cache purges all of the dirty blocks invalidates all of the cache blocks and sets all of the cache statistics to zero To purge all of the dirty blocks in the cache select Cache gt Purge Thi
10. FIFTEEN mov x0 5 clear swi SWI_CLEAR_LINE mov x0 6 mov r1 ldr r2 InvBlue sui SWI_DRAW_STRING mov ri 0 mov r0 10 BL Display8Segment CKBLUELOOP mov xrO0 10 clear sui SWI CLEAR LINE mov r 4 clear sui SWI_CLEAR_LINE mov r0 1 mov r1 4 ldr r2 TestBlue sui SWI DRAW STRING mov r0 10 mov ri 4 mov r2 r4 swi SWI_DRAW_INT subs r4 r4 1 bne BLUELOOP Prepare to exit draw a message mov mov ldr r0 1 r1 10 sui Turn off both ldr swi r2 Bye SWI_DRAW_STRI LED s NG 0 0 SWI S ETLED 8 segment bla mov swi nk r0 0 SWI_SETS 8 ldr r3 2000 previous line column number row number pointer to string draw to the LCD screen clear 8 segment previous line column number row number pointer to string draw to the LCD screen clear 8 segment previous line previous line display number of tests give only 15 tests to the lcd screen on line 10 lst message and clear the board column 1 column number row number pointer to string draw to the LCD screen delay a bit 40 ARMSim User Guide BL Wait Clear the LCD screen swi SWI CLEAR DISPLAY swi SWI EXIT all done exit Display8Segment Number RO Point R1 Displays the number 0 9 in RO
11. It does not implement every feature that can be found on the ARM Some of the more important limitations are listed belovv 18 ARMSim User Guide e The ARM architecture supports both little endian and big endian access to memory The ARM Sim supports only the little endian format the same as the Intel architecture which hosts the ARMSim e The ARM architecture has a special mode of execution called Thumb mode which is intended for embedded system applications where memory is a scarce resource Each thumb instruction occupies only 2 bytes Thumb mode is not currently supported by ARMSim 8 SWI Codes for I O in ARMSim the first Plug in Plug ins have been used to extend the functionality of ARMSim in a modular fashion A full descrip tion of the Plug in designs is beyond the scope of this document The default installation of ARMSim comes with two Plug ins module extensions SWIInstructions and EmbestBoard The SWllnstructions plug in implements SWI codes to extend the functionality of ARMSim for common I O operations and its use is detailed in this section Important Note All Plug ins have to be enabled explicitly by checking their option in the File gt Preferences menu and selecting the appropriate line from within the tab labelled Plugins 8 1 Basic SWI Operations for I O The SWI codes numbered in the range 0 to 255 inclusive are reserved for basic instructions that ARM Sim needs for I O and should not be altered T
12. LCD screen 9 0 1 Detailed Descriptions and Examples for SWI Codes for the Embest Board Plug in Set the 8 Segment Display to light up swi 0x200 The appropriate segments light up to display a number or a character The pattern of segments to be lit up is assigned to register RO before the call to swi 0x200 Figure 14 shows the arrangements of seg ments and an example follows Each segment is logically labelled and its byte code is shown in the list in Table 6 For example in Figure 14 to display the number 3 segments A B C D and F must be illuminated The code to be assigned to R is computed by the logical OR of the individual byte codes 26 ARMSim User Guide Figure 14 The Pattern for the 8 Segment Display A as Table 6 Segmen t byte values G B Display byte values 0x80 0x40 0x20 0x10 0x08 0x04 0x02 old l Val Ul gt 0x01 Example number 3 plus dot CD CD As an example the number 3 plus the right hand dot would have a pattern value computed as the logical OR of the values of the segments A B C D F P to form the integer 0x80 0x40 0x20 0x08 0x02 0x10 xFA to be assigned to 10 Below some segments of code are shown as examples for the 8 segment Display The equ statements are useful for accessing the b
13. LED 0x02 bit patterns for LED lights equ RIGHT LED 0x01 egu LEFT BLACK BUTTON 0x02 bit patterns for black buttons egu RIGHT BLACK BUTTON 0x01 Qand for blue buttons egu BLUE KEY 00 0x01 button 0 egu BLUE KEY 01 0x02 button 1 egu BLUE KEY 02 0x04 button 2 equ BLUE KEY 03 x08 button 3 egu BLUE KEY 04 0x10 button 4 equ BLUE KEY 05 x20 button 5 equ BLUE KEY 06 x40 button 6 equ BLUE KEY 07 x80 button 7 egu BLUE KEY 00 1 lt lt 8 button 8 different vay to set egu BLUE KEY 01 1 lt lt 9 button 9 egu BLUE KEY 02 1 lt lt 10 button 10 egu BLUE KEY 03 1 lt lt 11 button 11 egu BLUE KEY 04 1 lt lt 12 button 12 egu BLUE KEY 05 1 lt lt 13 button 13 egu BLUE KEY 06 1 lt lt 14 button 14 egu BLUE KEY 07 1 lt lt 15 button 15 10 4 Example Subroutine to implement a wait cycle with the 32 bit timer Wait Delay r2 wait for r2 milliseconds Wait stmfdsp 1 r0 r1 1r 33 ARMSim User Guide sui SWI GetTicks mov ri r R1 start time WaitLoop sui SWI GetTicks subs r0 r0 rl RO time since start rsbltr0 0 0 fix unsigned subtract cmp r r2 bit WaitLoop WaitDone ldmfdsp r0 r1 pc 10 5 Example Subroutine to check for an interval with a 15 bit timer Embest Board The timer in ARMSimf is implemented using a 32 bit
14. SEG C 6 SEG A SEG B SEG C 47 SEG 5 5 C SEG D SEG E SEG F SEG G 48 SEG A SEG 5 5 G SEG C 49 0 Blank display An example of a possible routine to display a number in the 8 segment Display using the declarations given above is shown in Figure 17 Register RO and R1 are input parameters where RO contains the integer to be displayed and R1 contains 1 to display the P segment or 0 othervvise Display8Segment Number RO Point R1 Displays the number 0 9 in RO on the LED 8 segment display If RI 1 the point is also shown 1 Display8Segment stmfd sp r0 r2 1r 2 ldr r2 Digits 3 ldr r0 r2 r0 1s1 2 4 tst r1 0x01 012 r1 1 5 orrne r0 r0 SEG P then show P 161 svi 0x200 Figure 17 A possible Display8Segment routine 7 ldmfd sp r0 r2 pc In line 3 register r 0 is assigned the byte value corresponding to the indexed element of the array digits from Figure 16 For example to display the number 3 after execution of line 2 the input register r0 should contain the integer value 3 and register r2 contains the address of the array Digits Then the computation implied by r2 r0 1s1 2 adds 12 bytes to the address currently in r2 i e r0 shifted left by 2 positions which evaluates to 3 x 4 12 and loads the word in position 3 of the array namely word SEG_A S
15. String to a File swi 0x69 Assume you have the following in your data section MatMsg asciz AnThis is the resulting matrix n 22 ARMSim User Guide Also assume that an output file has been opened as shovvn above and that its name is stored in Out FileName and its file handle is stored in OutFileHandle Then the following lines of code print the string lt nThis is the resulting matrix n to the output file opened as shown above The string is preceded and followed by a new line since the char acter n is embedded at the end of the string ldrr0 OutFileHandle load the output file handle ldrr r0 RO file handle ldrr1 MatMsg R address of string SviSNI PrStr output string to file VVrites the supplied string to the current position ldr r0 OutFileHandle in the open output file The file handle passed in ldr rO r0 r0 must have been obtained by an earlier call to ldr r1 TextString the Open File swi operation swi 0x69 bes WriteError Note The special file handle value of 1 can be used to write a string to the Stdout output win dow of ARMSim giving the same behaviour as swi 0x02 A brief example appears on the right Read String from a File swi 0x6a Reads a string from a file The input file is identi fied by a file handle passed in RO R1 is the address of an area into which the string is to be copied R2 is the maximum number of bytes
16. counts and runtimes Selecting the tab labelled Stdin Stdout Stderr brings a window to the front where output from the user program is displayed as a result of using software interrupts SWI instructions to perform I O Output directed to either the standard output or standard error Stdin Stdout are displayed in this tabbed window Any request to read from the standard input device Stdin causes the program to freeze until the input is provided on the keyboard that input is echoed in this tabbed window as well 14 ARMSim User Guide To copy text from the one of the Output View tabbed windows right click in the view and select Copy to Clipboard from the context menu To clear the contents of the Output Vievv tabbed vvindovv right click in the tab and select Clear from the context menu 6 4 Stack Vievv The Stack View displays the contents of the system stack In this view the memory address of a value and its binary representation are displayed on a single line separated by a colon and displayed in hexa decimal format Furthermore the top vvord in the stack is highlighted see Figure 10 Note that the sys tem stack is a full descending stack experiments Gt EE Console Stcin Stdout Stder Loading assembly language file C ARMSim 150 testFiles experiment s The following assembler loader errors occurred File C ARMSim 150 testFiles experiment s Line 6 Column 10 Message Undefined symbol A1
17. on the 8 segment display If RI 1 the point is also shown Display8Segment stmfd sp r0 r2 1r ldr r2 Digits ldr r0 r2 r 15142 tst r1 0x01 gif r1 1 orrne r0 r0 SEG P then show P swi SWI_SETSEG8 ldmfd spi r0 r2 pc Wait Delay r3 wait for r3 milliseconds Delays for the amount of time stored in r3 for a 15 bit timer Wait stmfd spi r r5 lr ldr r4 0x00007FFFE mask for 15 bit timer SWI SWI_GetTicks Get start time and EL 60 14 adjusted time to 15 bit Wloop SWI SWI GetTicks Get current time and r2 r0 r4 adjusted time to 15 bit cmp raped blt Roll rolled above 15 bits sub ro e2 T 3 comput asy elapsed time bal CmpLoop Roll sub r5 r4 r1 compute rolled elapsed time add ESTO 2 CmpLoop cmp r5 r3 415 elapsed time delay bit Wloop Continue with delay Xwait ldmfd sp r0 r5 pc data Velcome asciz Welcome to Board Testing LeftLED asci LEFT light RightLED asciz RIGHT light PressBlackL asciz Press a BLACK button Bye asciz Bye for nov Blank asciz 2 Digits word SEG A SEG B SEG C SEG D SEG E SEG G 800 word SEG B SEG C 01 word SEG_A SEG_B SEG_F SEG_E SEG_D 02 word SEG_A SEG_B SEG_F SEG_C SEG_D 03 word SEG_G SEG_F SEG_B SEG_C 04 word SEG
18. quantity and the current time as number of ticks is accessed by using the SWI instruction with operand 0x 6d the corresponding EQU is set to be SWI_Get Ticks It returns in RO the number of ticks in milliseconds On the other hand the timer on the Embest board uses only a 15 bit quantity and this can cause a problem with rollover Assume one checks the time at a starting point T1 and then later at point T2 and one needs to test whether a certain amount of time has passe Ideally computing 12 T1 and comparing it to the desired interval is enough The range in ARMSim with a 32 bit timer is between 0 and 232 1 4 294 967 295 As milliseconds this gives a range of about 71 582 minutes which is normally enough to ensure that one can keep checking the intervals T2 T1 without T2 ever going out of range in a single program execution The range in the Embest board with a 15 bit timer is between and 215 1 32 767 giving a range of only 32 seconds When checking the interval T2 T1 there is no problem as long as T2 gt T1 and T2 lt 32 767 However it can happen that T1 is obtained close to the top of the range and T1 subsequently has a value after the rollover thus T2 lt T1 It is not enough to flip the sign as the following examples show Let T1 1 000 and T2 15 000 Then T2 T1 14 000 gives the correct answer for the interval Subse quently let T1 30 000 and the later T2 2 000 afte the timer has rolled over If one simply calculates T
19. will be overwrit ldr r0 OutFileName ten otherwise a new file is created If r1 2 an mov r1 1 output mode existing text file is opened in append mode so swi SWI_Open that any new text written to the file will be added bes NoFileFound at the end ldr r1 OutFileHandle If the file is opened successfully a positive num str ro r1 ber the file handle is returned in r0 Otherwise ae a result of 1 is returned and the C bit is set OutFileHandle word 0 InFileHandle word 0 InFileName asciz Infilel txt OutFileName asciz Outfilel txt Note The default location for the file is the same folder as the assembler source code file If another loca tion is desired a full path to the file location can be used For example the code shown below opens or creates a text file in the Windows Temporary directory ldrr0 PathName movr1 1 output mode SwiSWI Open PathName asciz C TEMP MyFile txt Close File swi 0x68 At the end of execution a file should be properly closed or else it may be inaccessible to other applica tions The following lines of code show how to close both the input and output files used as examples above load the file handle ldr r0 InFileHandle Closes a previously opened file Unless a file is oe shite swi SWI_Close closed it often cannot be inspected or edited by another program e g TextPad 55055 prog 5 ldr r0 OutFileHandle ldr ro r0 swi SWI_Close Write
20. 0 00000000 6 65006 5453006 474E4952 0A736920 0A002200 20646E61 7 20736177 6E756F66 00001240 74612064 736 7020 6F697469 04002062 20736177 20746F6E 6E756F66 00000064 00001260 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 Figure 7 Memory Vievv When an instruction is executed using one of the step commands see section 5 1 or when a sequence of instructions is executed using the Debug gt Run option or the Continue button see section 4 3 any memory locations that vvere vvritten to during the execution of the instruction s are highlighted after the execution of the instruction s has finished The properties of main memory including its starting address the stack area and the heap area can be customized to suit the user s preferences To change these properties select File gt Preferences and click the Main Memory tab Type in nevv values for the starting address stack area and heap area or use the arrow buttons beside each property to adjust the value of that property see Figure 8 Click OK and then reload the program see section 5 3 to refresh the Memory View s Notes If a store STR instruction is executed but the value in memory does not change check the Cache Preferences to make sure that the Write Policy is not set to Write Back If it is set it to VVrite Through See section 6 5 for information on setting the Cache Preferences e The simulator can have multi
21. 2 T1 28 000 or even tries to get its absolute value the answer is incorrect The value for the interval should be 32 767 T1 T2 32 767 30 000 2 000 4 767 which represents the correct number of ticks which passed between T1 and T2 Two things need to be done for correct programming First of all the timing value obtained in 32 bits in ARMSim should be masked to be only a 15 bit quantity so that the code will work both in the simula tor and on the board Secondly the testing for the interval include a test for rollover egu Secl 1000 1 seconds interval equPointlSec 100 0 1 seconds interval egu EmbestTimerMask Ox7fff 15 bit mask for timer values egu Topl5bitRange Ox0000ffff 215 1 32 767 text start movr6 0 counting the loops not necessary ldrr8 Topl5bitRange ldrr7 EmbestTimerMask ldrr10 PointlSec SWISWI GetTicks Get current time T1 movr1 r0 RI is TI andrl rl r7 Tl in 15 bits RepeatTillTime addr6 r6 1 count number of loops not necessary 34 SWISWI_GetTicks Get current time T2 movr2 r0 4 R2 is T2 andr2 r2 r7 8 T2 in 15 bits cmpr2 r1 is T2 gt T1 bgesimpletime subr9 r8 r1 TIME 32 676 T1 addr9 r9 r2 T2 balCheckInt Simpletime subr9 r2 r1 TIME 2 1 Checklnt cmpr9 r10 Qis TIME lt interval bitRepeatTillTime SuiSNI EXIT
22. EG_B SEG_F SEG_C SEG_D In fact this uses the segments A B C D F to display the correct number In line 4 the content of r1 is tested If r1 1 then the segment P is added to the display with its value ORed with the previous ones in r0 28 ARMSim User Guide Set the two LEDs to light up swi 0x201 mov r0 40x02 swi 0x201 left LED on Light up the LEDs the left or the right or both mov r 0x01 according to the value supplied by r0 swi 0x201 right LED on mov r0 40x03 swi 0x201 both LEDs on Check if one of the Black Buttons has been pressed svvi 0x202 The call with swi 0x202 sets the content of r0 swi 0x202 as r0 2 if the left black button was pressed or cmp ro 40x02 r0 1 if the right black button was pressed Test beg ActOnLeftBlack ing 10 enables follow up actions bal ActOnRightBlack Check if one of the Blue Buttons has been pressed swi 0x203 After the call with swi 0x203 test the content swi 0x203 of r0 The number r0 corresponds to the posi cmp r0 1 tion of the blue button as depicted in Figure For cmp r0 2 example if r0 2 then the blue button in posi cmp r0 3 tion 2 was pressed The keypad with 16 blue buttons as depicted in the board view umimm VA Keyboard for input m They are arranged such that each button has a corresponding bit position in the 16 bit lower portion of a word in register RO after the call to swi 0x203 to poll the
23. G Vic The ARMSimi User Guide R N Horspool VV D Lyons M Serra Department of Computer Science University of Victoria 1 Overvievv ARMSimf is a desktop application running in a Windows environment It allows users to simulate the execution of ARM assembly language programs on a system based on the 7 processor ARMSimf includes both an assembler and a linker when a file is loaded the simulator automatically assembles and links the program ARMSimf also provides features not often found in similar applications They enable users both to debug ARM assembly programs and to monitor the state of the system while a program executes The monitoring information includes both cache states and clock eycles con sumed The purpose of this user guide is to explain how to use the tools and views provided by ARMSimf Therefore the scope of the document has been limited to the features of the simulator It does not cover ARM assembly programming or computer architecture Users vvho are unfamiliar vvith these topics should consult other material some of vvhich is listed in the references E ARMSimulator lx ARMSimulator University of Victoria Produced by Dr Nigel Horspool Dale Lyons Dr Micaela Serra Department of Computer Science Copyright 2006 University of Victoria All rights reserved For use by CSC230 students and staff only The topics in this document have been organized to provide a step by step int
24. Sim The ARM Simulator Dept of Computer Science DER File View Cache Debug Watch Help Docked Window in W L gr a 2 3 A Ise the pin To toggle between The show and W Onur Wingo auto hide modes and use the X to hide the view WatchWiew se The tabs To select one iew from a stack of views Figure 1 Docking Windows 3 2 Board Controls View the plug ins and the SWI instructions While ARMSim can be used completely on its own the extra features of plug ins and I O instructions can be extremely useful They have to be enabled explicitly even when installed at the same time Plug ins see below are seen as configurable additions to provide extra functionality normally as a graphical view of I O e g a board with buttons and lights One other very important extension is the use of pre selected SWI instructions to implement I O functionalities such as reading and writing from stan dardinput or output or files see below ARMSim User Guide In order to enable these features click on File and Preferences and then select the tab Plugins The avail able modules as loaded in the ARMSimf directory are listed and need to be checked for enabling 3 3 Fonts To change the font size style or colour of the text in a view move the cursor into the view click the right mouse button and select Font from the context menu Then make changes in the Font dialog box and clic
25. ariable from the watch list select the variable in the Watch View and then select Watch gt Remove Watch To remove all of the variables from the watch list select Watch gt Clear All Alterna tively right click in the Watch View and select Clear All from the context menu Notes e Although Remove Watch appears in the Watch menu this option has not yet been implemented e The Watch View does not display arrays however it is possible to display the first item of an array by treating it as a scalar variable and adding it to the watch list as described above EE AddWatch Labels SubStringSearchS s igi Display s Integer Format G o C Byte Signed Halfword a Word Base Character Decimal String C Hexadecimal OK Cancel Watc h view Lahe Value tens 1000000000 Figure 6 Adding a Watch 6 2 Memory View A Memory View displays the contents of main memory In this view each row contains an address fol lowed by a series of words from memory see Figure 7 Since the entire main memory cannot be displayed in a single Memory View each Memory View shows only a part of memory The address in the top left corner of the view specifies the word at which the part 12 ARMSim User Guide of memory displayed in the vievv begins and the size of the vievv determines the number of vvords dis played To display a different part of memory enter a hexadecimal address from 0 to FFFFFFFF i
26. at the given position of the LCD rl y position coordinate iscreen on the LCD screen 0 14 r2 Address of a null ter minated ASCII string Note x y 0 0 is the top left and 0 14 is the bot tom left The display is limited to 40 characters per line 25 ARMSim User Guide Table 5 SWI operations greater than OxFF as currently used for the Embest board Plug In Opcode Description and Action Inputs Outputs swi 0x205 swi 0x206 Display an integer on the LCD screen Clear the display on the LCD screen r0 x position coordinate on the LCD screen 0 39 rl y position coordinate on the LCD screen 0 14 r2 integer to print Note x y 0 0 is the top left and 0 14 is the bot tom left The display is limited to 40 characters per line None The string is displayed starting at the given position of the LCD screen Blank LCD screen swi 0x207 Display a character on the LCD screen r0 x position coordinate on the LCD screen 0 39 rl y position coordinate on the LCD screen 0 14 r2 the character Note x y 0 0 is the top left and 0 14 is the bot tom left The display is limited to 40 characters per line The string is displayed starting at the given position of the LCD screen swi 0x208 Clear one line in the dis play on the LCD screen r0 line number y coordi nate on the LCD screen Blank line on the
27. cking on the Floating Poin tab in the Registers View The Floating Point Registers can be viewed as Single Precision or Double Precision registers Use the Sin gle Precision or Double Precision tabs at the top of the Registers View to switch between the display types see Figure 4 ARMSim User Guide 5 Debugging a Program ARMSim provides a number of features that enable users to debug ARM assembly programs includ ing execution controls to step through and restart programs Reload and Open Multiple commands and breakpoints Sections 5 1 and 5 2 describe the execution controls Sections 5 3 and 5 4 describe the Reload and Open Multiple commands respectively and section 5 5 explains hovv to manage break points 5 1 Stepping Through a Program To step through a program one instruction at a time use either the Step Into button or the Step Over button on the toolbar or alternatively select Debug gt Step Into or Debug gt Step Over After an instruction has been executed using either Step Into or Step Over both the next instruction to be executed and any memory locations in the Registers Memory and Cache Views that were written to during the execution of the instruction are highlighted For most instructions the results of both Step Into and Step Over are identical hovvever when an instruction is a branch to a subroutine Step Into executes the branch and moves to the first instruction of the subroutine In contrast th
28. e Output View for compiler errors see section 6 3 When the file is opened it is automatically assembled if it is a source file and linked 5 5 Breakpoints A breakpoint is a user defined stopping point in a program i e a point other than an SWI 0x11 instruc tion at which execution of a program should terminate When a program is being debugged break points are used to halt execution of the program at predefined points so that the contents of storage locations such as registers and main memory can be examined to ensure that the program is working correctly When a breakpoint is set and the program is run using either the Debug gt Run option or the Continue button see section 4 3 execution of the program stops just before execution of the instruction at which the breakpoint is set see Figure 5 10 ARMSim User Guide To set a breakpoint double click the line of code at which the breakpoint should be set Alternatively step through the code to the line at which the breakpoint should be set and then select Debug gt Toggle Breakpoint VVhen the breakpoint is set a large red dot appears in the Code Vievv next to the address of the instruction at vvhich the breakpoint vvas set To clear a breakpoint double click the line of code at which the breakpoint is set Alternatively step through the code to the line at which the breakpoint is set and then select Debug gt Toggle Breakpoint To clear all of the breakpoint
29. e Step Over executes the vvhole subroutine and moves to the instruction after the branch in the original subroutine Therefore if a program consists of multiple files and there is a branch from a subroutine in one file to a subroutine in another file executing the branch using Step Into also changes the file displayed in the Code Vievv 5 2 Restarting a Program To restart a program click the Restart button on the toolbar or select Debug gt Restart Restarting a pro gram resets the registers cache and memory it sets the program counter to the address of the first instruction in the program and it highlights this instruction the next instruction to be executed 5 3 Reloading a Program To reload a program click the Reload button on the toolbar or select File gt Reload Reloading a pro gram loads a new copy of the file from the hard drive it resets the registers cache memory stack and vvatches it sets the program counter to the address of the first instruction in the program and it high lights this instruction the next instruction to be executed 5 4 Opening Multiple Files To open multiple files select File gt Open Multiple Then click the Add button in the MultiFileOpen dialog box navigate to the folder in vvhich the files are stored and double click the file to be opened Repeat the three steps in the previous sentence until all of the files to be opened have been added to the listin the dialog box Then click OK
30. en using the Cache Preferences Form to set the cache properties begin by selecting the type of cache Table 3 lists the available cache configurations Then set the size of the cache s Once the Cache Size has been set selecting a value for either the Block Size or the Number of Blocks causes the remaining set tings in the Cache Size box to assume the appropriate values so that the three properties satisfy the fol lovving equation Cache Size bytes Block Size bytes x Number of Blocks 16 ARMSim User Guide Next select the Associativity of the cache s If Set Associative is selected set the Blocks per Set and select a Replacement Strategy Finally select the Write and Allocate Policies for the Cache or Data Cache Table 3 Cache Configurations Configuration Settings Unified Data and Instruction Cache Enable the Unified Data and Instruction Cache Separate Data and Instruction Caches Disable the Unified Data and Instruction Cache and enable the Data Cache and the Instruction Cache Data Cache Only Disable the Unified Data and Instruction Cache and the Instruction Cache and enable the Data Cache Instruction Cache Only Disable the Unified Data and Instruction Cache and the Data Cache and enable the Instruction Cache No Cache Disable the Unified Data and Instruction Cache the Data Cache and the Instruction Cache General Main Memory Cache Unified Data and Instruction Cache
31. ents of the registers can be displayed in hexadecimal unsigned decimal or signed decimal formats Additionally the contents of the Vector Floating Point Coprocessor VFP registers can be displayed They include the overlapped Single Precision Registers s0 s31 and the Double Precision Floating Point Registers d0 d15 Output Viev Console It displays any automatic success and error messages produced by the sim ulator Output Viev It displays any text printed to standard output Stdout Stdin Stdout Stderr Stack Vievv It displays the contents of the system stack In this view the top word in the stack is highlighted VVatch Vievv It displays the values of variables that the user has added to the vvatch list that is the list of variables that the user vvishes to monitor during the execu tion of a program Cache Views They display the contents of the L1 cache This cache can consist of either a unified data and instruction cache displayed in the Unified Cache View or separate data and instruction caches displaved in the Data Cache and Instruction Cache Views respectively depending on the cache properties selected by the user Board Controls View It displays the user interfaces of any loaded plug ins If no plug ins were loaded at application start this view is disabled Memory View It displays the contents of main memory as 8 bit 16 bit or 32 bit words There can be multiple memory
32. evious line sui SWI CLEAR LINE mov r0 6 column number mov r1 5 row number ldr r2 InvBlue pointer to string sui SWI_DRAW_STRING draw to the LCD screen mov rl 0 mov r0 10 clear 8 segment BL Display8Segment bal CKBLUELOOP ELEVEN mov r0 5 clear previous line sui SWI_CLEAR_LINE mov r 6 column number mov r1 5 row number ldr r2 InvBlue pointer to string sui SWI_DRAW_STRING draw to the LCD screen mov rl 0 mov r0 10 clear 8 segment BL Display8Segment bal CKBLUELOOP INELVE mov r0 5 clear previous line sui SWI CLEAR LINE mov r0 6 column number mov r1 5 row number ldr r2 InvBlue pointer to string sui SWI_DRAW_STRING draw to the LCD screen mov xl 0 mov r0 10 clear 8 segment BL Display8Segment bal CKBLUELOOP IHIRTEEN mov 0 45 clear previous line swi SWI CLEAR LINE mov r0 6 column number mov r1 5 row number ldr r2 InvBlue pointer to string sui SWI_DRAW_STRING draw to the LCD screen mov r1 0 mov r0 10 clear 8 segment BL Display8Segment 39 ARMSim User Guide bal CKBLUELOOP FOURTEEN mov x0 5 clear sui SWI_CLEAR_LINE mov x0 6 mov rl 5 ldr r2 InvBlue sui SWI DRAW STRING mov r1 0 mov r0 10 BL Display8Segment bal CKBLUELOOP
33. heir list is shown in Table 4 and examples of their use fol low The use of EQU is strongly advised to substitute the actual numerical code values The right hand column shows the EQU patterns used thoughout this document in the examples Table 4 SWI VO operations 0x00 Opcode Description and Action Inputs Outputs EQU swi 0x00 Display Character on Tr the character SWI_PrcChr Stdout swi 0x02 Display String on T address of a null ter see also 0x69 Stdout minated ASCII string belovv swi 0x11 Halt Execution SNI Exit swi 0x12 Allocate Block of Mem T block size in bytes r0 address of block SW1 MeAlloc ory on Heap swi 0x13 Deallocate All Heap SWI_DAlloc Blocks swi 0x66 File T file name i e address of r0 file handle SWI_Open mode values in r1 are 0 la null terminated ASCII If the file does not for input 1 for output 2 string containing the name open a result of 1 for appending r1 mode is returned swi 0x68 Close File T file handle SWI_Close swi 0x69 Write String to a File or T file handleor Stdout SWI_PrStr to Stdout r1 address of a null termi nated ASCII string 19 ARMSim User Guide Table 4 SWI VO operations 0x00 OxFF ticks ticks milliseconds Opcode Description and Action Inputs Outputs EQU swi Read String from a F
34. ile 0 file handle 10 number of SWI_RdStr r1 destination address bytes stored r2 max bytes to store swi 0x6b VVrite Integer toa File T file handle SWI_Print r1 integer swi 0x6c Read Integer from a File r0 file handle T the integer SWI_RdInt svi 0x6d Get the current time 10 the number of SWI_Timer 8 1 1 Detailed Descriptions and Examples for SWI Codes for I O Display Character on Stdout swi 0x00 A character is a 1 byte entity The SWI used with equ SWI register 0 The lines of code below print the character labelled A to the Stdout followed by the new line character 0x00 instruction from the SWI table of the simulator normally _PrChr 0x00 can print such a character to the stdout view when assigned to Note that the assignment of a character to a register needs the single left quote in the syntax for the immediate operand Displays one character in the output window Display String on Stdout swi 0x02 Displays a string in the output window See also the more general swi 0x69 below Halt Execution swi 0x11 Stops the program Allocate Block of Memory on Heap swi 0x12 Obtain a new block of memory from the heap area of the program space If no more memory is available the special result 1 is returned and the C bit is set in the CPSR mov r0 A svi PrChr mov r0 Nn svi PrChr ldr r0 MyString svi 0x02 MyString asciz Hello There n svi SWI Exit mov
35. imal and Unsigned Decimal buttons at the top of the Registers View to switch between display formats see Figure 3 When an instruction is executed using one of the step commands see section 5 1 or when a sequence of instructions is executed using the Debug gt Run option or the Continue button see section 4 3 any reg isters and condition code flags that were written to during the execution of the instruction s are high lighted after the execution of the instruction s has finished Registersview Use these buttons to switch Registers R10 R15 are also labelled between the Hexadecimal Unsigned Decimal and Table 3 Hexadecimal Unsigned Decimal Signed Decimal Signed Decimal display r 0001240 modes R10 s stack limit R2 100001246 0000 0000 R11 fp frame pointer Registers that were 00000000 itten to durine th R12 lip intra procedure call scratch R6 00000000 CIE register R7 00000000 execution of the last R8 00000000 instruction or j 00000000 R13 stack pointer seguence of instruc R tions R14 link register L2 2p 00005340 R15 Jpc program counter 1 5 pc 100001010 Condition Code Flags Overflov V IRQ Disable FIQ Disable CPU Mode an l 10x000000df CPSR Current Program Status Register Figure 3 General Purpose Registers View The Floating Point Registers are selected by cli
36. k OK To restore the original font settings move the cursor into the view click the right mouse but ton and select Restore Defaults from the context menu Note that Restore Defaults will also restore the default background and highlight colours 3 4 Colours To change the background highlight colour in a view move the cursor into the view click the right mouse button and select Background Colour Highlight Colour from the context menu Then make the changes in the Color dialog box and click OK To restore the original background and highlight colours move the cursor into the view click the right mouse button and select Restore Defaults from the context menu Note that Restore Defaults will also restore the default font settings The use of the highlight colour depends on context For example in the Code and Stack Views it is used as a background colour on the highlighted line but in the Register and Cache Views it is used as a text colour for storage locations that have been written to 4 Getting Started Using ARMSim to simulate the execution of a program on an ARM processor involves two activities actually running the program and observing the output Sections 4 1 to 4 4 provide information on run ning programs with the simulator while sections 4 5 and 4 6 describe two of the views available in the simulator 4 1 Creating a File ARMSim accepts both ARM assembly source files that use the Gnu Assembler gas syntax and
37. keypad The number labels placed in the figure which do not appear on the real keypad also represent the corresponding bit position as returned in R VVhen a button is pressed the corresponding bit is set For example when the button in position 1 is pressed the swi 0x203 instruction returns r0 0x02 thatis r0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 in binary where the bit in position 1 has been set Figure 18 The Pattern for the Blue Buttons 29 ARMSim User Guide Display a string on the LCD screen swi 0x204 mov r0 44 Display the string whose address is supplied in mov r1 1 r2 on the LCD screen at position x y where ldr r2 Message r0 x and r1 y In this example r0 4 and swi 0x204 display message r1 y 1 that is line 1 at column 4 Message asciz Hello There n Display an integer on the LCD screen svvi 0x205 mov r0 44 mov r1 41 mov r2 123 swi 0x205 display integer Display an integer on the LCD screen The inte ger is in r2 to be shown at position x y where r0 x and r1sy In this example r2 23 r0 4 and r1 y 1 that is line 1 at column 4 displays 23 Clear the display on the LCD screen swi 0x206 Clear the whole LCD screen 0226 l Display a character on the LCD screen svvi 0x207 Display a character on the LCD screen The char mov T 4 acter is in r2 to be shovvn at position x y mov
38. l StartsWith 00001040 E 1405000 mov r5 r0 00001044 E 8BDO0O0OF 1dmf d r131 r0 r3 Figure 2 Code Vievv VVhen a file is opened and successfully assembled and linked its contents are displayed in the Code View as described above and the first instruction to be executed is highlighted When multiple files are opened see section 5 4 the file in which execution must start is displayed in the Code View with the first instruction highlighted The other files can be vievved by clicking on the tabs at the top of the Code View ARMSim User Guide 4 6 Registers View The Registers View displays the contents of the 16 general purpose user registers available in the ARM processor as well as the status of the Current Program Status Register CPSR and the condition code flags the leftmost 4 bits of the CPSR as displayed below the condition code flags in the simulator Additionally the Vector Floating Point VFP registers are available for display in the tab labelled Float ing Point These registers represent the 32 Single Precision registers or the 16 Double Precision Regis ters of the VFP Note that these two sets of registers are overlapped The General Purpose Registers are selected by clicking on the General Purpose Registers tab in the Registers View The contents of the general purpose registers can be displayed in hexadecimal signed decimal or unsigned decimal formats Use the Hexadecimal Signed Dec
39. me asciz whatever txt FileOpenInpErrMsg asciz Failed to open input file n EndOfFileMsg asciz End of file reached n ColonSpace asciz NL asciz NT new line 32 Messagel end 10 3 Example ARMSim User Guide asciz Hello World An Useful patterns for using SWI Instructions for a Plug In This is a possible initial template to set the useful SVVI codes for the Embest Board Plug in egu SWI_SETSEG8 0x200 display on 8 Segment egu SWI SETLED 0x201 LEDs on off egu SWI_CheckBlack 0x202 check Black button egu SWI_CheckBlue 0x203 check press Blue button egu SWI DRAW STRING 0x204 display a string on LCD egu SNI DRAW INT 0x205 display an int on LCD equ SWI_CLEAR_DISPLAY 0x206 clear LCD equ SWI_DRAW_CHAR 0x207 display a char on LCD egu SWI CLEAR LINE 0x208 clear a line on LCD egu SWI EXIT 0x11 terminate program equ SWI_GetTicks Ox d get current time equ SEG_A 0x80 patterns for 8 segment display equ SEG_B 0x40 byte values for each segment egu SEG C 0x20 of the 8 segment display egu SEG D 0x08 egu SEG E 0x04 egu SEG F 0x02 egu SEG G 0x01 egu SEG P 0x10 egu LEFT
40. na ee eee ee 10 6 Additt nab VIEWS zis Secesc a 11 6 1 Watch V W 11 i00 710s0r An ra nn 11 6 2 Memory Veys oa O a a EN NTR 12 6 3 G tp b Veys l An 14 6 4 Stack VTevy s AI D DU TE 15 6 5 Cache VIEWS peee 16 a Some ARMSim Limitations V 18 8 SWI Codes for VO in ARMSim the first Plug in 19 8 1 Basic SWI Operations for 1 19 8 1 1 Detailed Descriptions and Examples for SWI Codes for VO 20 9 SWI Operations for Other Plug Ins the Embest Board Plug In 24 9 0 1 Detailed Descriptions and Examples for SWI Codes for the Embest Board Plug in26 10 Con op 921 1 leo ne Eee Ca nee a 30 10 1 Example Print Strings Characters and Integers to Stdout using SWI Instructions for 1 030 10 2 Example Open and close files read and print integers using SWI Instructions for I O 31 10 3 Example Useful patterns for using SWI Instructions for a Plug In 5222 33 10 4 Example Subroutine to implement a wait cycle with the 32 bit timer 33 10 5 Example Subroutine to check for an interval with a 15 bit timer Embest Board 34 10 6 Example Using the SWI Instructions for a Plug In Embest Board View 35 ARMSim User Guide Sections 2 and 3 begin vvi
41. nd move to the next instruction in the current subroutine If the highlighted instruction is a subroutine call BL or BX instruction then the program is run until the subroutine returns Thus unless a breakpoint is encountered the next highlighted instruction vvill be at the return point from the subroutine call 1 Iml The Stop button causes the simulator to stop the execution of the program The Continue button causes the simulator to run the program until it encounters a breakpoint an SWI 0x11 instruction end of execution or a run time error The Restart button causes the simulator to start the execution of the program from the begin ning The Reload button causes the simulator to load a new version of the program file from the hard drive and start the execution of the program from the beginning le izi Elle 2 2 Views The ARMSim views display the simulator s output and the contents of the system s storage ARMSim provides several views which are summarized in Table 2 ARMSim User Guide Table 2 ARMSim Views Code View Registers View It displays the assembly language instructions of the program that is cur rently open This view is always visible and cannot be closed It displays the contents of the 16 general purpose user registers available in the ARM processor as well as the status of the Current Program Status Reg ister CPSR and the condition code flags The cont
42. nto the text box in the top left corner of the Memory View Alternatively use the up and down arrows beside the text box to select lovver and higher memory addresses respectively The contents of memory can be dis played as 8 bit bytes 16 bit halfwords or 32 bit words Use the three buttons in the Word Size box in the top right corner of the Memory View to switch among the three display formats MemoryViev 2 e address of The first word where The Word Size 1000 display of memory in this view begins ho vi isplay of ry 8 BBit 16Bit 32Bit 00001000 59003 25900000 E59F1035 2 5911000 E59F4034 E2405001 00001020 59 3026 E2500001 2777 E2511001 aie 00001040 000011 00001054 00001060 00000002 00000003 00001080 E3403000 5014000 00001040 224000002 EZ2811001 00001000 0000 0400000 101400 0004 14000001 EAFFFFFS E3400000 ESBLG TE Memory locations that were written to during the execution 0001 E3A0002B 4000000 E3A0002D of the last instruction or seguence of instructions 0001 0017 14000000 3 06001 0004 44000006 000002 0800004 00001140 E3500000 00002 21401000 E2855001 EAFFFFF3 3550000 14000001 E3560001 57 1 9 3 06001 57 7 4 20001 r s ESLFD040 ES C20000 3406004 0224695 Use these buttons to switch between the 8 bit 16 bit and 32 bit display modes 00989680 F4240 0001864 00002710 0000038 00000064 00000004 00000001 00000000 0000000
43. ple Memory Views each of which displays a different region of memory To open additional Memory Views select View gt Memory 13 ARMSim User Guide e When the display size is set to 8 bit the ASCII representation of each row of bytes is displayed at the end of the rovv e When the display size is 16 bit or 32 bit the assignment of byte addresses is little endian Inthe Memory View all cells that are part of the memory region allocated to the program are shown in hexadecimal notation e g E1A03000 00000000 cells outside the allocated memory region are shown as question marks e g preferencesForm General Main Memory Cache Starting Address of Main Memory Stack Area KB Heap Area KB Memory Fill Pattern 81818181 Stop program on misaligned memory access Cancel OK Figure 8 Main Memory Preferences Form 6 3 Output View The Output View contains a row of two tabs labelled Console and Stdin Stdout Stderr Selecting the tab labelled Console brings a window to the front where the simulator outputs success and error mes sages After the simulator has loaded the program any assembler or linker errors are displayed here see Figure 9 for an example To find the source of an error message displayed in the Output View see Fig ure 9 double click the message and scroll up one line in the Code View Additional information will be displayed here such as instruction
44. r ldr r2 PressBlue pointer to string sui SWI_DRAW_STRING draw to the LCD screen mov r4 16 36 get button press into RO if zero previous line previous line BLUELOOP wait for user to press blue button mov r0 0 BB swi SWI_CheckBlue cmp r0 0 beq BB cmp r0 BLUE KEY 15 beg FIFTEEN cmp r0 BLUE KEY 14 beg FOURTEEN cmp r0 BLUE KEY 13 beg THIRTEEN cmp r0 BLUE KEY 12 beg TWELVE cmp r0 BLUE KEY 11 beg ELEVEN cmp r0 BLUE KEY 10 beg TEN cmp r0 BLUE KEY 09 beg NINE cmp r0 BLUE KEY 08 beg EIGHT cmp r0 BLUE KEY 07 beg SEVEN cmp 0 BLUE KEY 06 beg SIX cmp 0 BLUE KEY 05 beg FIVE cmp r0 BLUE KEY 04 beg FOUR cmp 0 BLUE KEY 03 beg THREE cmp r0 BLUE KEY 02 beg TWO cmp r0 BLUE KEY 01 beg ONE cmp r0 BLUE KEY 00 mov r0 5 clear svi SWI CLEAR LINE mov r1 0 mov x0 0 BL Display8Segment bal CKBLUELOOP ONE mov x0 5 clear svi SWI_CLEAR LINE mov r1 0 mov r0 1 BL Display8Segment no button pressed ARMSim User Guide 37 ARMSim User Guide
45. r0 28 get 28 bytes swi SWI_MeAlloc ldr r1 Address str r0 r1 Address word 20 ARMSim User Guide Deallocate AlI Heap Blocks svvi 0x13 Causes all previously allocated blocks of memory svi DAlloc in the heap area to be considered as deallocated thus allowing the memory to be reused by future requests for memory blocks Open File svvi 0x66 Opening a file for input Assume the follovving in the data section InFileName asci Infilel txt InFileError asciz Unable to open input file n align InFileHandle word 0 The following lines of code open the file called Infilel txt for input and store its file handle returned in RO by the opening call into the appropriate memory location ldr r0 InFileName set Name for input file mov 11 0 2 mode is input swi SWI Open open file for input bes InFileError if error ldr r1 InFileHandle load input file handle str r0 r1 save the file handle Thus to open a file for input one needs to load the address of the string containing the file name into RO set the input mode 0 into R1 and execute the SWI instruction with 0x66 as operand By testing the carry bit upon return using the BCS instruction one makes sure that the file has been opened properly othervvise a message should be printed and the program should exit Opening a file for outpu
46. r1 1 where here r0 x and r1 y In this example mov r2 4 Z r23 Z r0 4 and r1 y 1 that is line 1 at column swi 0x207 display char 4 displays Z Clear one line in the display on the LCD screen swi 0x208 Clear only one line on the LCD screen where the ldr r0 5 line number is given in r0 swi 0x208 clear line 5 10 Code Examples 10 1 Example Print Strings Characters and Integers to Stdout using SWI Instructions for I O PRINT STRINGS CHARACTERS INTEGERS TO STDOUT egu SWI_PrChr 0x00 Write an ASCII char to Stdout egu SWI PrStr 0x69 Write a null ending string egu SWI_PriInt 0x6 b Write an Integer 2 equStdout 1 Set output mode to be Output View egu SWI Exit 0x11 Stop execution global start text start print a string to Stdout mov RO Stdout mode is Stdout 30 ARMSim User Guide ldr Rl Messagel load address of Messagel swi SWI PrStr display message to Stdout print a new line as a string to Stdout mov RO Stdout mode is Stdout ldr r1 EOL end of line swi SWI Prstr print a character to the screen mov RO A RO char to print sui SWI PrChr print a blank character from data ldr r0 Blank ldrb r0 r0 R char to print blank sui SWI PrChr print a second character to Stdout mov RO B RO char to print sui SWI PrChr print a new line as a cha
47. racter to Stdout ldr r0 NewL ldrb r0 r0 RO char to print sui SWI PrChr print an integer to Stdout mov RO Stdout mode is Output view mov rl 42 integer to print swi SWI Print print a new line as a string to Stdout mov R Stdout mode is Output view ldr r1 EOL end of line sui SWI PrStr swiSWI Exit 8 stop executing end of program new line data Messagel asciz Hello World EOL asciz NewL ascii m n Blank ascii end 10 2 Example Open and close files read and print integers using SWI Instructions for I O OPEN INPUT FILE READ INTEGER FROM FILE PRINT IT CLOSE INPUT FILE egu SWI Open 0x66 open a file egu SW1 Close 0x68 close a file egu SWI_PrChr 0x00 Write an ASCII char to Stdout equSWI_PrStr 0x69 Write a null ending string egu SWI_PriInt 0x6b Write an Integer egu SWI_RdInt 0x6c Read an Integer from a file equStdout 1 Set output target to be Stdout egu SWI Exit 0x11 Stop execution global start text start print an initial message to the screen 20 Co DD DB 31 ARMSim User Guide
48. roduction to ARMSim including the extra features regarding I O instructions based on custom SVVI codes and plug ins The table of contents below summarizes the items described 1 In this document a view is a window displayed by the ARMSim simulator that shows the state of some aspect of the program being run ARMSim User Guide Table of Contents 1 DV OLY OW asses esata on 1 2 Feature Sranane aa r da Da Ra s 3 2 1 TOOID ARs zosik non a a a eas EE EE TEER S 3 2 2 WIEWS GN E N ii 3 3 Setting up the SITU ALOR v 4 3 1 Docking Windowsis tienes 0 4 3 2 Board Controls View the plug ins and the SWI instructions 2222 5 3 3 BONUS aa E E 00000 u a i 6 3 4 aa fini eSBs CARER Ae 00 00 ie dist een nah aes 6 4 SOU AT CS gos 6 4 1 Creating a File aaa nana na du 6 4 2 Opening and Loading a File 6 4 3 Running A PLO STATI mirin dieses shove taste YR aaa by ASIB 7 4 4 St pping a Program y R D as 7 4 5 Code VIEW s yd y ERA hn nn 7 4 6 Registers VIG 3042222000 00 0 0000 00 8 5 DS Die Se a ruzi 9 5 1 Stepping Through a 9 5 2 Restarting a Progtam pasov 9 5 3 Reloading a Program iee aee reo Eene Ee 9 5 4 Opening M ltiple a anna 9 5 5 ik Re
49. s command has no effect unless the Write Policy is set to Write Back To view the cache statistics including the hit and miss rates select Cache gt Statistics To clear all the cache statistics click the Reset button on the Cache Statistics display Note e The Instruction Cache is sometimes referred to as the Code Cache UnifiedCacheView 7222222 7227227 1772277777 7727777 7227272 ES e59f003c e5900000 e59f1036 25911000 00001010 e59f4034 e2405001 e3a06004 20224695 77777777 77777777 7777777 77777777 7777777 25973028 e2500001 44000004 2511001 Cache Block 1222272722 222 1222272 7222272 7 44000002 e4124004 e4834004 eafffffe Memory Address PPP PP 7227227 7727777 7227277 7227772 J K 00001040 ef000011 00001054 00001058 0000105 Cache block that was written to 72777777 77777777 7777777 7777777 7777777 during the execution of the last instruction or seguence of 00001050 00001068 00000003 00000003 00000001 instructions 79777997 1797777777 72777777 1779777777 7777777 s t 1060 00000002 00000003 00000003 00000000 Dirty Block 77797999 77777777 117777777 1777177777 1177177 77797999 77777777 0117777779 77777777 1777777 77999999 7797779 7077977 71777777 7777977 Figure 12 Cache Vievv 7 Some ARMSim Limitations The ARMSimf is an aid for learning the operation of the ARM architecture
50. s in a program select Debug gt Clear AlI Breakpoints Note e Clear AlI Breakpoints clears the breakpoints in all files that are currently open ReverseCopy s When the program 1s run execution stops just before execution of the instruction where the breakpoint is set Figure 5 Breakpoints 6 Additional Views In addition to the Code and Register Views discussed in sections 4 5 and 4 6 respectively ARMSim includes Watch Memory Output Stack and Cache Views that enable users to observe the data trans fers within the system as well as the output of the system The following sections describe these addi tional views and explain any commands and settings associated with them 6 1 Watch View The Watch View displays the values of variables that the user has added to the watch list which is a list of variables that the user wishes to monitor during the execution of a program To add a variable to the watch list select Watch gt Add Watch Alternatively right click in the Watch View and select Add Watch from the context menu In the Add Watch dialog box see Figure 6 select the file in which the variable appears the label that is attached to the variable and the display type of 11 ARMSim User Guide the variable If applicable specify the integer format of the variable and select the base in vvhich the integer representation of the variable should be displayed Click OK To remove a v
51. screen vvhich is a grid of 40 columns by 15 rovvs of individual cells The coordi nates for each LCD cell are specified by a column row pair The top left cell has coordinates 0 0 while the bottom right cell has coordinates 39 14 Each cell can contain exactly one ASCII charac ter Table 5 SWI operations greater than OxFF as currently used for the Embest board Plug In Opcode Description and Action Inputs Outputs swi 0x200 Light up the 8 Segment T the 8 segment Pattern The appropriate segments light Display see below in Figure 14 for up to display a number or a details character swi 0x201 Light up the two LEDs 10 the LED Pattern Either the left LED is on or the where right or both Left LED on 0x02 Right LED on 0x01 Both LEDs on 0x03 i e the bits in position 0 and 1 of r0 must each be set to 1 appropriately swi 0x202 Check if one of the Black None 10 the Black Button Pattern Buttons has been pressed where Left black button pressed returns 10 0x02 Right black button pressed returns 10 0x01 i e the bits in position 0 and 1 of T get assigned the appropri ate values swi 0x203 Check if one of the Blue None see below in Fig 0 the Blue Button Pattern see Buttons has been pressed ure for details belovv in Figure swi 0x204 Display a string on the T x position coordinate The string is displayed starting LCD screen on the LCD screen 0 39 l
52. sult is returned in r0 swi 0x6c If a properly formatted number is not found in bes ReadError the input the C bit is set and r0 is unchanged By 4 the integer is now in r0 testing the carry bit upon return using the BCS instruction one makes sure that the integer has been read properly 9 SWI Operations for Other Plug Ins the Embest Board Plug In The SWI codes numbered greater than 255 have special purposes They are mainly used for interaction with Plug in modules which can be loaded with the ARMSim simulator Table 5 provides a current list of these codes as they are used in the Embest Board Plug in View Examples of their use follow with illus trations of the corresponding component The use of EQU is strongly advised to substitute the actual numerical code values Examples of code is also provided at the end of the section A diagram representing schematically the features of the Embest board is shown in Figure 13 A 8 segment Tvvo LED lights wo buttons for input display for output for output VA Keyboard for input Figure 13 A diagrammatic vievv of the available controls and displays on the Embest Board View There are 5 main components in this vievv available for programming 1 One 8 segment display output 2 Two red LED lights output 24 ARMSim User Guide Two black buttons input Sixteen blue buttons arranged in a keyboard 4 x 4 grid input 5 One LCD display
53. t Assume the follovving in the data section OutFileName asciz Outfilel txt OutFileError asciz Unable to open output file n align OutFileHandle vord 0 The following lines of code open the file called Out filel txt for output and store its file han dle returned in RO by the opening call into the appropriate memory location ldr r0 0utFileName set Name for output file mov r1 f 1 mode is output swi SWI Open open file for output bes OutFileError if error ldr r1 0utFileHandle load output file handle ser 40 ri save the file handle Thus to open a file for output one needs to load the address of the string containing the file name into RO set the output mode 1 into R1 and execute the SWI instruction with 0x66 as operand By testing the carry bit upon return using the BCS instruction one makes sure that the file has been opened prop erly or else a message should be printed and the program should exit 21 ARMSim User Guide Summary of the swi 0x66 file opening instruction ldr r0 InFileName mov r1 0 input mode swi SWI_Open Opens a text file for input or output The file bcs NoFileFound name is passed via r0 Register r1 specifies the file ldr r1 InFileHandle access mode If r1 0 an existing text file is to be str ro r1 opened for input If r1 1 a file is opened for out bane put if that file exists already it
54. th the features of the simulator and explain hovv to customize its layout Sec tion 4 describes the most commonly used debugging features and vievvs Sections 5 and 6 conclude by detailing additional debugging features vievvs and performance monitoring tools Section 8 includes details about the extra features of ARMSim namely the I O instructions built on custom SWI codes implemented as as external Plug in Section 9 introduces the Plug in feature vvith detailed examples of use based on the currently available modules 2 Features The ARMSim toolbar and views give the user access to a variety of tools to debug and monitor ARM assembly language programs The follovving sections describe the controls provided by the toolbar and the information displayed in the vievvs 2 1 Toolbar The ARMSim toolbar provides easy access to many of the debugging features of the simulator espe cially those features that allovv the user to control the execution of a program The functions of the but tons on the toolbar are summarized in Table 1 Table 1 Toolbar Buttons The Step Into button causes the simulator to execute the highlighted instruction and move to the next instruction in the program If the highlighted instruction is a subroutine call BL or BX instruction then the next highlighted instruction vvill be the first instruction of the subroutine M The Step Over button causes the simulator to execute the highlighted instruction a
55. to store into memory One line of text is read from the file and copied into memory and a null byte terminator is stored at the end The line is trun cated if it is too long to store in memory The result returned in r0 is the number of bytes including the null terminator stored in memory Write Integer to a File swi 0x6b Converts the signed integer value passed in r1 to a string and writes that string to the file identified by the file handle passed in r0 Assumes that an output file has been opened and that its name is stored in OutFileName and its file handle is stored in OutFileHandle The lines of code on the right print the integer 42 contained in reg ister R1 to the opened output file CharArray TextString asciz Answer mov r0 1 ldr r1 Message swi 0x69 display message Message asciz Hello There n ldr r0 InFileHandle ldr roO r0 ldr r1 CharArray mov r2 80 svi x6a bos ReadError InFileHandle vord 0 skip 80 ldr ldr mov svi r0 OutFileHandle ro r0 r1 42 SWI_Print 23 ARMSim User Guide Note The special file handle value of 1 can be mov r0 1 used to write the integer to the Stdout output mov r1 99 window An example appears on the right swi 0x6b display 99 Read Integer from a File swi 0x6c Reads a signed integer from a file The file is ldr r0 InputFileHandle identified by the file handle passed in r0 The ldr r0 r0 re
56. to open the files VVhen the files have been successfully opened the contents of the file that contains the start or main subroutine vvill appear in the Code Vievv vvith the first instruction in this subroutine highlighted To remove a file from the list of files to be opened select the filename in the dialog box and click the Remove button To remove all of the files from the list of files to be opened click the Clear button Notes e The files to be opened must be ARM assembler source s files ARM object o files or a combi nation of source and object files e If a file does not appear in the directory listing in the dialog box one must check that the appro priate file type has been selected ARMSim User Guide Registersview General Purpose Floating Point aa d0 23 14159 Use these buttons to switch between the Single or Double precision Floating Point Registers di dz 28319 JA that were written d3 F 71828 during the execution of the last instruction or sequence of instructions d6 7 38901 d7 20 0855 FCPSR Register Negative N 0 Zero Z 20 Carry C Overflow V Stride Length m 0x00000000 Figure 4 Floating Point Registers View Condition Code Flags oo oo FPCPSR Floating Point Current Program Status If the contents of the file appear in the Code View but the first instruction is not highlighted check th
57. views each displaying a different region of memory 3 Setting up the Simulator The appearance of ARMSimf including the location font and colour of the views can be customized to suit the user s preferences When the simulator is closed the settings are remembered for next time the user starts up ARMSim The following sections describe how to customize ARMSim s appearance 3 1 Docking Windows All of the views described in section 2 2 except the Code View appear in docking windows see Figure 1 Each window can be docked along any side of the application window or it can float above the appli ARMSim User Guide cation window In addition each docking window can be displaved or hidden and each displayed win dovv has an auto hide option To move a docking window click the title bar of the window and drag the window to the desired loca tion If multiple vievvs have been stacked vvithin a single docking vvindovv select the tab vvith the desired vievv name from the tabs along the bottom of the docking vvindovv click this tab and drag it to the desired location To toggle a docking vvindovv betvveen the shovv and hide states select the vievv name from the Vievv menu Alternatively to hide a docking window that is currently displayed click the X in the top right corner of the docking vvindovv To toggle a docking vvindovv betvveen the shovv and auto hide modes click the pin in the top right corner Fal ARM
58. yte values associated vvith the labels of each segment as shovvn in Figure 14 An example of a possible declaration of data is also given in Figure 16 for the display of integers where the byte values representing a particular number are already ORed together vvithin the array data structure and can be indexed appropriately t may be easier to use a data declaration for an array of words and then index into it Each element can be initialized to contain the value representing a number by having the appropriate byte values ORed together Use equ statements to set up the byte value of each segment of the Display egu SEG A 0x80 egu SEG B 0x40 egu SEG C 0x20 egu SEG D 0x08 egu SEG E 0x04 egu SEG F 0x02 egu SEG G 0x01 egu SEG P 0x10 Figure 15 Possible data declaration for byte values for segments 27 ARMSim User Guide Digits word A possible data dec word laration for an array word of words which can word be indexed to obtain word the appropriate word value for a number word 0 9 to be dis word plaved word word word Figure 16 Possible data declaration forinteger patterns SEG A SEG 5 C SEG D SEG E SEG G 20 SEG B SEG C 41 SEG 5 5 F SEG E SEG D 02 SEG A SEG B SEG 5 C SEG 3 SEG G SEG F SEG B SEG C 04 SEG A SEG G SEG F SEG C SEG D 85 SEG A SEG G SEG F SEG E SEG D

Download Pdf Manuals

image

Related Search

Related Contents

こちらに掲載いたしました「デベロッパー向け販売  取り扱い説明書はこちら  Typical In-Tank Electric Fuel Pump Installation Instructions    INT-TSI  HCS544/HCS544X Day Night Camera Quick Install Guide  Installation Manual PPT8/12/16/22L/LY  untitled  FT tatin foie gras oignon RHD 100g  Ubiquiti Networks airGateway  

Copyright © All rights reserved.
Failed to retrieve file