Hi guys,
I'm trying to figure out how to use both C and ASM in my programming. I am mainly using PIC18F4550 assembly, but there are things that are just much easier in C that I would eventually just like to code up really quick, and call it from assembly. For example, if you were helping me with my other post, I was trying to do some simple hex to bcd conversions that was just a nightmare for me. Plus, you can't divide or multiply by non-integers.
Anyways, let's get to the point. As a small assignment, I have three .c files named bottom.c, middle.c, and top.c. I need to replace middle.c with middle.asm (I make this).
middle.c:
As I was starting with my middle.asm file, I kinda realized I don't use arguments in any of my function calls since I store the data all in registers.
This is what I have so far in my middle.asm:
Here are my questions:
1) When it's just a local variable, is it best to just use "local" or should I just make a variable at the top by doing "middlelocal res 1."
2) How do I call a C function from assembly that has arguments?
3) How do I make a function in assembly language that uses arguments?
I was trying to search for tutorials, but all I can find are tutorials for C or for asm.
I'm trying to figure out how to use both C and ASM in my programming. I am mainly using PIC18F4550 assembly, but there are things that are just much easier in C that I would eventually just like to code up really quick, and call it from assembly. For example, if you were helping me with my other post, I was trying to do some simple hex to bcd conversions that was just a nightmare for me. Plus, you can't divide or multiply by non-integers.
Anyways, let's get to the point. As a small assignment, I have three .c files named bottom.c, middle.c, and top.c. I need to replace middle.c with middle.asm (I make this).
middle.c:
Rich (BB code):
#include "P18F4550.h" //local copy of version found in MCC18 directory
int bottom (int dividend, int divisor);
int middle(int arg1, int arg2)
{
int middlelocal;
middlelocal = arg1;
middlelocal += bottom(arg1, arg2);
return middlelocal;
}
This is what I have so far in my middle.asm:
Rich (BB code):
LIST P=18F4550
#include "P18F4550.INC"
extern bottom
middle:
; Define middlelocal variable (since it's an int, should I res 4 bytes?)
local middlelocal
; Get arg2
movff TOSU,arg2U
movff TOSH,arg2H
movff TOSL,arg2L
; Get arg1
pop
movff TOSU,arg1U
movff TOSH,arg1H
movff TOSL,arg1L
; Set middlelocal = arg1?
movff arg1L,middlelocal
; TODO: Push variables onto stack, but not sure what to do with middlelocal
return
end
1) When it's just a local variable, is it best to just use "local" or should I just make a variable at the top by doing "middlelocal res 1."
2) How do I call a C function from assembly that has arguments?
3) How do I make a function in assembly language that uses arguments?
I was trying to search for tutorials, but all I can find are tutorials for C or for asm.
Last edited: