CS代考 GY 6483 Real Time Embedded Systems

MORE ON ASSEMBLY PROGRAMMING
EL-GY 6483 Real Time Embedded Systems

A SIMPLE C PROGRAM

Copyright By PowCoder代写 加微信 powcoder

int total;
total = 0;
for (i = 10; i > 0; i–) { total += i;

ARM EQUIVALENT
MOV R0, #0 ; R0 accumulates total MOV R1, #10 ; R1 counts from 10 to 1 again ADD R0, R0, R1
SUBS R1, R1, #1
halt B halt ; infinite loop to stop

MEMORY INSTRUCTIONS
addInts MOV R4, #0 addLoop LDR R2, [R0] ADD R4, R4, R2
ADD R0, R0, #4
SUBS R1, R1, #1 BNE addLoop

MORE ADDRESSING MODES
addInts MOV R4, #0 addLoop SUBS R1, R1, #1 LDR R2, [R0, R1, LSL #2] ADD R4, R4, R2
BNE addLoop

WHAT DOES THE ASSEMBLER DO?
MOV R3, R9
1110 0001 1010 0000 0011 0000 0000 1001

HELLO WORLD FOR ARM ASSEMBLY
.global _start _start:
MOV R7, #4 MOV R0, #1 MOV R2, #12 LDR R1, =string SWI 0
MOV R7, #1 SWI 0
.ascii ”Hello World\n”

CALLING ARM ASSEMBLY FROM C
#include
extern void strcopy(char *d, const char *s);
int main()
{ const char *srcstr = ”First string – source ”;
char dststr[] = ”Second string – destination ”;
/* dststr is an array since we’re going to change it */
printf(”Before copying:\n”);
printf(” %s\n %s\n”,srcstr,dststr);
strcopy(dststr,srcstr); // in strcopy.s
printf(”After copying:\n”);
printf(” %s\n %s\n”,srcstr,dststr);
return (0); }8

CALLING ARM ASSEMBLY FROM C
AREA SCopy, CODE, READONLY
EXPORT strcopy
strcopy ; R0 points to destination string.
; R1 points to source string. LDRB R2, [R1],#1 ; Load byte and update address.
STRB R2, [R0],#1 ; Store byte and update address.
CMP R2, #0 BNE strcopy BX lr
; Check for null terminator. ; Keep going if not.

INLINE ASSEMBLY EXAMPLES
Calling assembly inline:
/* NOP example */
__asm(”mov r0,r0”);

Variable Constraints

INLINE ASSEMBLY EXAMPLE
int foo(int x, int y) {
SUBS x,x,y BEQ end
return 1; end: return 0; }

ARM CALLING CONVENTION
Register r0-r3 r4-r10 r11
r13 r14 r15
arguments passed, r0 holds result
local variables, callee-save
frame pointer
intra-procedure-call scratch register
stack pointer link register program counter
Additional parameters and return values may be passed via stack.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com