Can anyone give me any information an writing assembler for arm using VC++ embedded tools.
An example would make all my dreams come true
An example would make all my dreams come true
A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.
AREA ArmGfxLib,CODE,READONLY
EXPORT FunctionA
EXPORT FunctionB
FunctionA
MOV r12, sp
stmfd sp!, {r4-r11,lr}
; useful code to do something goes here!
ldmfd sp!, {r4-r11,pc}
FunctionB
MOV r12, sp
stmfd sp!, {r4-r11,lr}
; useful code to do something goes here!
ldmfd sp!, {r4-r11,pc}
END
armfunction
MOV r12, sp ; these two lines are
stmfd sp!, {r4-r11,lr} ; standard setup code
; r0-r3 are the first 4 arguments passed
ldr r4, [r12] ; load 5'th argument into r4
ldr r5, [r12, #4] ; load 6'th argument into r5
add r0, r0, r1 ; r0 = r0 + r1
add r0, r0, r2 ; r0 = r0 + r2
add r0, r0, r3 ; r0 = r0 + r3
add r0, r0, r4 ; r0 = r0 + r4
add r0, r0, r5 ; r0 = r0 + r5
ldmfd sp!, {r4-r11,pc} ; standard cleanup and return code
; TITLE("clear_screen")
;++
;
;
; Module Name:
;
; clear_screen.s
;
; Abstract:
;
; Test procedure to compile and run on my IPAQ... (keyword there is test)
;
;
AREA screen_writer, CODE, READONLY ; name this block of code
EXPORT clear_screen_arm
; simple, unoptimised CLS routine, hard-coded to a 16bpp 320x240 screen.
; Takes address of screen in R0
; colour in R1
clear_screen_arm
stmfd sp!, {r0-r12,r14}
add r1,r1,r1,lsl #16 ; colour into both pixels please
mov r2,r1
mov r3,r1
mov r4,r1
mov r5,r1
mov r6,r1
mov r7,r1
mov r8,r1
mov r9,r1
mov r10,r1
mov r11,r1
mov r12,r1
mov r14,#320
clear_screen_arm_inner
stmia r0!,{r1-r12} ; store 24 pixels in one shot.
stmia r0!,{r1-r12} ; store 24 pixels in one shot.
stmia r0!,{r1-r12} ; store 24 pixels in one shot.
stmia r0!,{r1-r12} ; store 24 pixels in one shot.
stmia r0!,{r1-r12} ; store 24 pixels in one shot.
stmia r0!,{r1-r12} ; store 24 pixels in one shot.
stmia r0!,{r1-r12} ; store 24 pixels in one shot.
stmia r0!,{r1-r12} ; store 24 pixels in one shot.
stmia r0!,{r1-r12} ; store 24 pixels in one shot.
stmia r0!,{r1-r12} ; store 24 pixels in one shot.
subs r14,r14,#1
bne clear_screen_arm_inner
ldmfd sp!, {r0-r12,pc}
ENDextern "C" void clear_screen_arm(DWORD,unsigned short);bool ClearScreen()
{
unsigned short * pusLine = (unsigned short *)GXBeginDraw();
if (pusLine == NULL) return false; // NOT OK TO DRAW, return failure.
// WARNING hard-coded for the purposes of it actually running on my iPAQ 3600
// gxbegindraw doesn't give me the first pixel of the display buffer,
// but the END pixel of the first line.
pusLine-=319;
clear_screen_arm((DWORD)pusLine,0xf81f); // 0xf81f = 1111100000011111 = red + blue = pink
GXEndDraw();
return false;
}bool ClearScreen(int colRed,int colGreen, int colBlue)(you can include a macro to compile your *.s files elsewhere in you project - this has already been discussed somewhere on this board, IIRC).
couldnt get it to compile
refractor wrote:Firstly, you can't (easily) embed ARM assembler in EVC++ (which *stinks*).
chuawenching wrote:
Why do we need ARM assembler for if we can use embedded visual c++?
Actually what is ARM? The microprocessor for pocket pc?
simonjacobs wrote:This is a FAQ for ARM assembler programming on the Pocket PC.
Maintained by Simon Jacobs
Version 1.0 (22'nd Jan 2002)
I have done my best to make this accurate and useful, but I make no guarantees. Remember that assembler programming is complex and if you are unsure of yourself you should ask for help. Please email me if there are any questions you would like to see added to the list.
--------------------------------------------------------------------------------
1) Is there a good book about ARM assembler?
2) Can I use inline assembler in my c code with Embedded Visual C++?
3) Can I see what assembler code the c compiler creates?
4) How do I add an assembley source file to my project, and get EVC to assemble it?
5) How do I write a function in assembler and call it from the c code?
6) How are values passed to and from the assembler function?
7) Can I use any of the 16 registers for anything?
Useful resources.
--------------------------------------------------------------------------------
1) Is there a good book about ARM assembler.
ARM System-on-chip architecture (second edition)
Steve Furber
Addison-Wesley
As well as some chapters aimed more at hardware designers, it has an explanation of the ARM instruction set plus a complete reference of the assembler format for each one. It doesnt teach programming in any way, but if you are experienced in c programming and just need full details of the instruction set and info on how the processor works it is great.
2) Can I use inline assembler in my c code with Embedded Visual C++?
There is no supported way of doing this. You need to put your assembler in seperate functions which can be called from your c code. See below for details of how to do this.
3) Can I see what assembler code the c compiler creates?
Yes, and this is very useful for a few reasons. You can see how optimal the code being produced is, and also learn how the compiler does things. You need to:
From the 'Project' menu choose 'Settings'. Go to the 'C/C++' tab. In the 'Category' drop-down-list choose 'Listing Files'. In the 'Listing file type' drop-down-list choose 'Assembley with Source Code'.
Now the compiler will produce .asm files in the output directory which contain the assembler code with the c source as comments.
4) How do I add an assembley source file to my project, and get EVC to assemble it?
Create a blank file 'myfile.asm' in your project directory with notepad. From the menu in EVC select 'Project->Add to Project->Files' set the 'Files of type' field to 'All Files' and select the myfile.asm file. It will appear in the file list on the left, drag it into the 'Source Files' section.
Select 'Project->Settings' from the menu. On the left of the dialog: select the 'ARM release' configuration and select the 'myfile.asm' file. On the right of the dialog: select the 'Custom Build' tab. In the 'Commands' box add the text 'armasm myfile.asm' and in the 'Outputs' box add the text 'myfile.obj'. Repeat this for the 'ARM debug' configuration.
Now you can open and edit myfile.asm from EVC and it will be assembled into your project.
5) How do I write a function in assembler and call it from the c code?
First a note about the assembler source code layout. All command lines should begin with a tab. Any lines that have text on the left are labels. You need to use labels for function names and as targets for branch instructions. Use a semicolon to mark the rest of a line as a comment. The file should finish with an END command.
Example file:
- Code:
AREA ArmGfxLib,CODE,READONLY
EXPORT FunctionA
EXPORT FunctionB
FunctionA
MOV r12, sp
stmfd sp!, {r4-r11,lr}
; useful code to do something goes here!
ldmfd sp!, {r4-r11,pc}
FunctionB
MOV r12, sp
stmfd sp!, {r4-r11,lr}
; useful code to do something goes here!
ldmfd sp!, {r4-r11,pc}
END
Explanation: the AREA command gives a name to this code section. The EXPORT command makes those labels available as functions. The stmfd/ldmfd commands save and restore the registers to the stack, so you dont corrupt values that the calling function depends on.
In your c++ code add the line:
#ifdef ARM
extern "C" void FunctionA(int a, int b);
#endif
The #ifdef is because we have written the function in ARM assembler so it isnt available in MIPS/SH3 builds.
6) How are values passed to and from the assembler function?
If you declare a function of the form:
extern "C" int armfunction(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
The first 4 arguments will be passed in the registers r0-r3. These registers will contain the passed values at the start of your assembler function. Further arguments are passed on the stack, see the code below to read them.
The return value should be placed into register r0 at the end of your assembler function (just before you return to the caller).
This works well with int's and pointers (all pointers are 32 bits). If you try and pass a structure directly as an argument it gets more complex. I advise you to only pass/return integers and pointers to/from your assembler functions, at least to start with.
Here is an example function (declared as above) which adds its six arguments and returns the result.
- Code:
armfunction
MOV r12, sp ; these two lines are
stmfd sp!, {r4-r11,lr} ; standard setup code
; r0-r3 are the first 4 arguments passed
ldr r4, [r12] ; load 5'th argument into r4
ldr r5, [r12, #4] ; load 6'th argument into r5
add r0, r0, r1 ; r0 = r0 + r1
add r0, r0, r2 ; r0 = r0 + r2
add r0, r0, r3 ; r0 = r0 + r3
add r0, r0, r4 ; r0 = r0 + r4
add r0, r0, r5 ; r0 = r0 + r5
ldmfd sp!, {r4-r11,pc} ; standard cleanup and return code
7) Can I use any of the 16 registers for anything?
No. You can use r0-r12 and r14 for anything you like. r15 is the program counter, if you write a value to it then execution will jump to that location. Use the branch instruction, dont alter it directly. r13 is the stack pointer, do not alter it unless you are sure you know what you are doing. r14 (which you can use) is the link register. If you want to call another function you need to set this to the return address, I will include an example in a future version of this FAQ.
Useful resources.
- <a href="http://www.ukscene.org/sulph/">sulphur's gba development site</a>
- <a href="http://www.intel.com/design/strong/manuals/">Intel StrongARM Manuals</a>
- <a href="http://www.geocities.com/wonglinhoo/Arm.htm">The Arm Microprocessor</a>
- <a href="http://www.soup-kitchen.net/armcode/">Soup Kitchen - Arm Tutorial</a>
- <a href="http://www.heyrick.co.uk/assembler/">ARM Assembler Programming</a>
- <a href="http://www.ee.ic.ac.uk/pcheung/teaching/ee2_computing/">ARM Assembly Lecture Notes</a>
- <a href="http://wheelie.tees.ac.uk/users/a.clements/ARMinfo/ARMnote.htm">The ARM Processor</a>
- <a href="http://re-eject.gbadev.org/">ARM Quick-Instruction reference sheet</a>
- <a href="http://www.gbadev.org/">gameboy advance development</a>