Word constant in inline-asembler

General discussion on mikroPascal PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
SamY Fareast
Posts: 46
Joined: 05 Aug 2007 07:15
Location: Shizuoka JAPAN

Word constant in inline-asembler

#1 Post by SamY Fareast » 12 May 2014 14:13

Hi all.
I wrote a small test program on mikroPascal PRO for dsPIC30/33 and PIC24.

Code: Select all

program const_in_asm;
const
  impl = 257;
  expl: word = 257;
begin
  { Main program }
  asm
    mov #_impl, w0
    mov #_expl, w1
    mov #257, W2
    mov #$0101, W3
  end;
And after compile this, I get const_in_asm.asm.

Code: Select all

_main:
	MOV	#2048, W15
	MOV	#6142, W0
	MOV	WREG, 32
	MOV	#1, W0
	MOV	WREG, 52
	MOV	#4, W0
	IOR	68

;const_in_asm.mpas,5 :: 		begin
;const_in_asm.mpas,8 :: 		mov #_impl, w0
	MOV	#1, W0
;const_in_asm.mpas,9 :: 		mov #_expl, w1
	MOV	#1, W1
;const_in_asm.mpas,10 :: 		mov #257, W2
	MOV	#257, W2
;const_in_asm.mpas,11 :: 		mov #$0101, W3
	MOV	#257, W3
;const_in_asm.mpas,13 :: 		end.
L_end_main:
L__main_end_loop:
	BRA	L__main_end_loop
; end of _main
Is there any way to get assembler code 'MOV #257, Wd' using constants declared outside of asm:end clause ?

aCkO
Posts: 1119
Joined: 14 Feb 2011 04:07
Location: Bar, Montenegro

Re: Word constant in inline-asembler

#2 Post by aCkO » 12 May 2014 17:33


SamY Fareast
Posts: 46
Joined: 05 Aug 2007 07:15
Location: Shizuoka JAPAN

Re: Word constant in inline-asembler

#3 Post by SamY Fareast » 13 May 2014 15:45

Thank you. aCkO.
That are very helpful page. But I could not find out smart solution there.

Now I only have ugly (and some what dangerous) way like below.

Code: Select all

program const_in_asm;
const
  impl = 255;
  expl: word = 257;
begin
  { Main program }
  asm
    mov #_impl, w0
    mov #_expl, w1
  end;
  { assign word constants at outside of 'asm'}
  W0 := impl;
  W1 := expl;
  asm
    CP W0, W1 // check values in asm
    BRA LT, TEST_1
    nop
   TEST_1:
    nop
  end;
end.
.asm

Code: Select all

;const_in_asm.mpas,5 :: 		begin
;const_in_asm.mpas,8 :: 		mov #_impl, w0
	MOV	#255, W0
;const_in_asm.mpas,9 :: 		mov #_expl, w1
	MOV	#1, W1
;const_in_asm.mpas,12 :: 		W0 := impl;
	MOV	#255, W0
;const_in_asm.mpas,13 :: 		W1 := expl;
	MOV	#257, W1
;const_in_asm.mpas,15 :: 		CP W0, W1 // check values in asm
	CP	W0, W1
;const_in_asm.mpas,16 :: 		BRA LT, TEST_1
	BRA LT	TEST_1
;const_in_asm.mpas,17 :: 		nop
	NOP
;const_in_asm.mpas,18 :: 		TEST_1:
TEST_1:
;const_in_asm.mpas,19 :: 		nop
	NOP
;const_in_asm.mpas,21 :: 		end.
L_end_main:
L__main_end_loop:
	BRA	L__main_end_loop
; end of _main

Post Reply

Return to “mikroPascal PRO for dsPIC30/33 and PIC24 General”