Instantly share code, notes, and snippets.

Embed
What would you like to do?
extern "C" {
int ASM_addsomenumbers(char small_number, int normal_number, long big_number);
long ASM_add4longs(long long_a,long long_b,long long_c,long long_d);
long ASM_addstack (long long_a,long long_b,long long_c,long long_d,long long_e);
}
.global ASM_addsomenumbers
ASM_addsomenumbers:
;add small_number to normal_number
add r24, r22
adc r25, r23
;add Low-Byte of big_number to previous result
add r24, r18
reti
.global ASM_add4longs
ASM_add4longs:
add r22,r18
adc r23,r19
adc r24,r20
adc r25,r21
add r22,r14
adc r23,r15
adc r24,r16
adc r25,r17
add r22,r10
adc r23,r11
adc r24,r12
adc r25,r13
reti
.global ASM_addstack
ASM_addstack:
; copy stackpointer into Z-Pointer
in r30, 0x3d
in r31, 0x3e
;add b to a, a is already in the return registers
add r22,r18
adc r23,r19
adc r24,r20
adc r25,r21
;add c to previous result
add r22,r14
adc r23,r15
adc r24,r16
adc r25,r17
;add d to previous result
add r22,r10
adc r23,r11
adc r24,r12
adc r25,r13
;load e form memory to registers
ldd r18, Z+3 ;Call Instruction increments Stack pointer +2
ldd r19, Z+4
ldd r20, Z+5
ldd r21, Z+6
;add e to previous result
add r22,r18
adc r23,r19
adc r24,r20
adc r25,r21
reti
#include <ASM_Memory.h>
// the setup routine runs once when you press reset:
void setup() {
static char str1[] = "Lorem Ipsum";
static int int_array[] = {1,2,3};
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println("Adding some numbers, 17,18,19");
Serial.println(ASM_addsomenumbers(17,18,19));
Serial.println("Adding 4 longs, 12,23,34,4");
Serial.println(ASM_add4longs(12,23,34,45));
Serial.println("Adding 5 longs, 12,23,34,45,56");
Serial.println(ASM_addstack(12,23,34,45,56));
}
// the loop routine runs over and over again forever:
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment