Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

asm & basic

Status
Not open for further replies.

Mosaic

Well-Known Member
Hi,
Need advice on transferring variables between basic to asm and back.

I need to do some asm operations on two basic word variables and then return a true or false bit to basic.

I am not sure how to access the word variables and return a bit since Oshon seems to move its variables around after each prg modification.

I guess i need to either have a dynamic way to transfer variables or define a static location of the variables.

thx
 
Oshonsoft allows you to use basic variables in asm!!

Code:
Symbolic names of global declared variables can be used in assembler routines because proper variable address will be assigned to those names by EQU directive:
Dim varname As Byte
varname = 0
ASM:        MOVLW 0xFF
ASM:        MOVWF VARNAME

When working with inline assembler code, it could be useful to use working register as a source or destination in assign statements. For that purpose WREG keyword should be used and the compiler will take care of the bank control:
Dim varname As Byte
ASM:        MOVLW 0xFF
varname = WREG

Makes it quite easy
 
hi,
This is the method I use when using ASM routines in Oshonsoft Basic

AllDigital

Dim ascbfr4 As Byte @ 0xa0; choose a free RAM area
Dim ascbfr3 As Byte @ 0xa1
Dim ascbfr2 As Byte @ 0xa2
Dim ascbfr1 As Byte @ 0xa3
Dim ascbfr0 As Byte @ 0xa4
Dim binnuml As Byte @ 0xa5
Dim binnumm As Byte @ 0xa6
Dim binnum As Word @ 0xa7
Dim temp1 As Byte @ 0xa9
Dim temp2 As Byte @ 0xaa

This fixes the RAM locations shared by ASM and Basic routines.

E.
 
Thx guys.
As an aside the reason I have to do this is I am encountering problems with a BAsic IRQ routine when attempting to do word comparisons such as
IF adc1>adc2 then temp = 100

For unknown reasons the irq goes into a loop and the prg never reaches the main code.

BTW it can be ANY word comparison, using different variables does not matter.

I don't have the time to walk thru the oshon asm to solve this right now.....
But I suspect it has to do with bank /page switching going awry.

My soln is to do my own asm comparisons and move on for now.
 
@ Ian, with your variable method...how does the asm select the correct bank for the variable location?

BTW, doing the asm compare solved the problem. Oshon WORD compare freaks out for some reason in the irq.
I created an asm function call that does the WORD compare and returns a byte value 0,1,2 based on =, >,< . then i use oshon to do BYTE based 'If..then' on the function result to finish the job.

Also I note that Oshon is NOW claiming 11 assembly errors and fails to produce a HEX. BUT when I compile the asm file (with MPASMWIN) that was generated by OSHON there are NO errors and the HEX runs properly.

Clearly OSHON needs some work.
 
Last edited:
Ok, let me whittle things down some to isolate the issue. There are a few hundred lines of code in this.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top