S12Z assembly error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S12Z assembly error

Jump to solution
1,788 Views
sergemonnerat
Contributor III

Hi,

I use CW11.1 and I work in assembly (for a course). I have several questions:

  1. The instructions sub d6,x,y don't compile, any idea ?

Capture1.JPG

  1. The instruction ld x,VAR (VAR: ds.p 1) don't work, the compiler translate this instruction by a LD x,0 and a LSR D3,D2,#1, very strange and the result is wrong :

Capture2.JPG

Best regards.

Serge

0 Kudos
1 Solution
1,756 Views
lama
NXP TechSupport
NXP TechSupport

I am very sorry for that. It is a bug as I was informed but I have found a workaround.

Please do not think about meaning of the code. Important is a workaround.


SUB_D6_X_Y: MACRO
                            dc.b $FD
                      ENDM

; code section
MyCode: SECTION
main:
_Startup:
Entry:
LD S, #__SEG_END_SSTACK - 1 ; initialize the stack pointer
CLI ; enable interrupts

LD D6,#$333333
EndlessLoop:

                  LD X, D6
                  LD Y, #$11
                  SUB_D6_X_Y
                  BRA EndlessLoop 

 

Best regards,

Ladislav

View solution in original post

0 Kudos
4 Replies
1,757 Views
lama
NXP TechSupport
NXP TechSupport

I am very sorry for that. It is a bug as I was informed but I have found a workaround.

Please do not think about meaning of the code. Important is a workaround.


SUB_D6_X_Y: MACRO
                            dc.b $FD
                      ENDM

; code section
MyCode: SECTION
main:
_Startup:
Entry:
LD S, #__SEG_END_SSTACK - 1 ; initialize the stack pointer
CLI ; enable interrupts

LD D6,#$333333
EndlessLoop:

                  LD X, D6
                  LD Y, #$11
                  SUB_D6_X_Y
                  BRA EndlessLoop 

 

Best regards,

Ladislav

0 Kudos
1,577 Views
sergemonnerat
Contributor III

Here all the errors found:

INCLUDE 'derivative.inc'
XDEF Entry, _Startup, main
XREF __SEG_END_SSTACK ; symbol defined by the linker for the end of the stack


DEFAULT_RAM: SECTION
V1B: DS.B 1
V1W: DS.W 1
V1P: DS.P 1
V2B: DS.B 2


DEFAULT_ROM: SECTION
CST1: DC.B $01,$02
CSTNOP: DC.B $01,$01,$01,$01


main:
_Startup:
Entry:

; Errors with MOV.B
MOV.B #%01111111, V1B ; ok
MOV.B #127, V1B ; ok
MOV.B #%10000000, V1B ; ko, wrong value
MOV.B #128, V1B ; ko, wrong value
MOV.B #$80, V1B ; solution, write the constant in hex

; Ok withMOV.W
MOV.W #%0111111111111111, V1W ; ok
MOV.W #32767, V1W ; ok
MOV.W #%1000000000000000, V1W ; ok
MOV.W #32768, V1W ; ok
MOV.W #$8000, V1W ; ok

; Error with LD X,address (same with Y)
MOV.P #$123456,V1P
CLR X
LD X, V1P ; ko, wrong opcode
LD X,$1103
patch01_LDX: DC.B $A8 ; solution, opcode from LD X followed by the address of V1P
patch01_V1P: DC.W V1P

; Errors with ST X,address (same with Y)
LD X, #$123456
ST X, V1P ; ko, wrong opcode
patch02_STX: DC.B $C8 ; solution, opcode from ST X followed by the address of V1P
patch02_V1P: DC.W V1P

; Errors with symbole+n
LD X, #V1P+15 ; ko, V1P+n with n<16 wrong value
V1P_15: EQU V1P+15 ; solution, use an equ
LD X, #V1P_15 ; ok
LD X, #V1P+16 ; ok, V1P+n with n>15

; Errors with CMP reg,var
CMP D0, V1B ; ko, wrong opcode
LD D1, V1B ; solution, use a second register
CMP D0, D1
CMP D2, V1W ; ko, wrong opcode
LD D3, V1W ; solution, use a second register
CMP D2, D3

; Error with SUB D6,X,Y
LD X, #V1B
LD Y, #V1W
;SUB D6, X, Y ; compiler error
patch03_SUB_D6_X_Y: DC.B $FD ; solution, opcode from SUB D6,X,Y

BRA main
NOP
NOP

0 Kudos
1,784 Views
kef2
Senior Contributor IV

Sorry, no comment

 

0 Kudos
1,579 Views
sergemonnerat
Contributor III

Here I have resume all the errors found ...

 

INCLUDE 'derivative.inc'
XDEF Entry, _Startup, main
XREF __SEG_END_SSTACK ; symbol defined by the linker for the end of the stack


DEFAULT_RAM: SECTION
V1B: DS.B 1
V1W: DS.W 1
V1P: DS.P 1
V2B: DS.B 2


DEFAULT_ROM: SECTION
CST1: DC.B $01,$02
CSTNOP: DC.B $01,$01,$01,$01


main:
_Startup:
Entry:

; Errors with MOV.B
MOV.B #%01111111, V1B ; ok
MOV.B #127, V1B ; ok
MOV.B #%10000000, V1B ; ko, wrong value
MOV.B #128, V1B ; ko, wrong value
MOV.B #$80, V1B ; solution, write the constant in hex

; Ok withMOV.W
MOV.W #%0111111111111111, V1W ; ok
MOV.W #32767, V1W ; ok
MOV.W #%1000000000000000, V1W ; ok
MOV.W #32768, V1W ; ok
MOV.W #$8000, V1W ; ok

; Error with LD X,address (same with Y)
MOV.P #$123456,V1P
CLR X
LD X, V1P ; ko, wrong opcode
LD X,$1103
patch01_LDX: DC.B $A8 ; solution, opcode from LD X followed by the address of V1P
patch01_V1P: DC.W V1P

; Errors with ST X,address (same with Y)
LD X, #$123456
ST X, V1P ; ko, wrong opcode
patch02_STX: DC.B $C8 ; solution, opcode from ST X followed by the address of V1P
patch02_V1P: DC.W V1P

; Errors with symbole+n
LD X, #V1P+15 ; ko, V1P+n with n<16 wrong value
V1P_15: EQU V1P+15 ; solution, use an equ
LD X, #V1P_15 ; ok
LD X, #V1P+16 ; ok, V1P+n with n>15

; Errors with CMP reg,var
CMP D0, V1B ; ko, wrong opcode
LD D1, V1B ; solution, use a second register
CMP D0, D1
CMP D2, V1W ; ko, wrong opcode
LD D3, V1W ; solution, use a second register
CMP D2, D3

; Error with SUB D6,X,Y
LD X, #V1B
LD Y, #V1W
;SUB D6, X, Y ; compiler error
patch03_SUB_D6_X_Y: DC.B $FD ; solution, opcode from SUB D6,X,Y

BRA main
NOP
NOP

0 Kudos