Binary numbers in ASM

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
slowfiddler
Posts: 7
Joined: Mon Sep 10, 2012 10:34 pm

Binary numbers in ASM

Post by slowfiddler » Wed Sep 12, 2012 5:43 pm

This trivial test compiles with the error:

"[ASM Error]: Error[113]test.asm 1007 : symbol not previously defined (B)"

Code: Select all

Sub Init()
Asm

movlw		b'00101000'
movwf		SSPCON1
clrf		SSPCON2

End Asm
End Sub

Init()

end
It compiles fine if I replace b'00101000' with 0x28

Is there a special syntax for giving numbers in binary format in Swordfish ASM? The form above is standard for MPASM I think.

Thanks

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Wed Sep 12, 2012 6:19 pm

The problem is that Swordfish sees the ' (single quote) as a comment, so the line is being removed by the preprocessor. It would be fair to argue that it should not do this between asm...endasm blocks but unfortunately, the preprocessor only works on a line by line basis.

In short, I'm afraid you will need to enter the number in hex (0x)

slowfiddler
Posts: 7
Joined: Mon Sep 10, 2012 10:34 pm

Post by slowfiddler » Wed Sep 12, 2012 9:46 pm

I feel a plugin coming on - a pre-preprocessor that converts the b'nnnnnnnn' into 0xnn. Or something.

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Thu Sep 13, 2012 8:21 am

I know this doesn't deal with your original question, but what's wrong with

Code: Select all

sub Init()
	SSPCON1 = %00101000
	SSPCON2 = 0
end sub
I think you'll find Swordfish is usually pretty good at generating code.

slowfiddler
Posts: 7
Joined: Mon Sep 10, 2012 10:34 pm

Post by slowfiddler » Thu Sep 13, 2012 11:00 am

Yes, that example would work just as well compiled from Basic. Actually, what I am trying to do is encapsulate some pretty tight atomic assembler routines from my existing product into Swordfish functions. Some of the routines have a lot of bitmasks that I would rather not convert to hex by hand.

slowfiddler
Posts: 7
Joined: Mon Sep 10, 2012 10:34 pm

Post by slowfiddler » Fri Sep 14, 2012 5:48 pm

Well well! This works:

Code: Select all

Sub Init()
Asm

movlw      00101000B
movwf      SSPCON1
clrf       SSPCON2

End Asm
End Sub

Init()

end
nnnnnnnnB is an obsolete way of entering binary numbers in MPASM according to the GPUtils docs.

Happy now.

Post Reply