Pic18 problem

Gast #2562262
Lesenswert?

Hallo, Ich habe ein seltsames Problem.
Das ist ein vom JAL generiertes code.

Beispiel:
1
 org 0x0008
2
p_73038_generated_aget: ; 26B1
3
  movlw   H'04'
4
  movwf   H'002'
5
  movf    H'002',w
6
  goto   _39635__vector
7

8

9
__indirection: 
10
  clrf    PCLATH  
11
  clrf    PCLATU  
12
  clrc    
13
  rlf     WREG, w  
14
  movwf   PCL    ; go to 0x0008

So geht es, aber wenn Ich es ändere in
1
p_73038_generated_aget: ; 26B1
2
  movlw   H'04'
3
  movwf   H'002'
4
  movf    H'002',w
5
  goto   _39635__vector
6

7

8
__indirection
9
  goto  p_73038_generated_aget
dann nicht mehr.Ich verstehe nicht warum.Kann das jemand vielleicht 
nachvollziehen?
Gast #2562595
Lesenswert?

Also das ist ein Teil einer routine, die einen Wert dezimahl auf dem 
display anzeigt.Das Problem ist halt, das wenn ich es ändere, dann das 
Wert nicht angezeigt wird.Es springt also zu der Marke und das Program 
hängt nicht, aber eben kein Wert angezeigt wird.
Und wieso ist es so komplieziert gemacht mit dieser Umleitung vertehe 
ich auch nicht.Wieso muss es am org 0x0008 stehen und nicht irgendwo 
sonst?
Gast #2562627
Lesenswert?

Hier ist noch die routine die diese "__indirection" aufruft
1
_57957__vector: ; 0FE0
2

3
;; 034 : procedure _print_base(byte volatile out target, -- the result
4
; var H'062:000' target
5

6
;; 035 : byte in x, -- the byte for printing
7
; var H'063:000' x
8

9
;; 036 : byte in out leader -- the leading zero
10
; var H'064:000' leader
11
p_57957__print_base: ; 0FE0
12
  movwf   H'064'
13

14
;; 038 :     if x == 0 then ; print a 0 ?
15
  movf    H'063',f
16
  btfss   H'FD8',2
17
  goto    if_57977_el
18
  ;a2nd   if_57977_el
19
if_57977_th: ; 0FE5
20

21
;; 039 :     if leader != 0 then -- there is a leader to be printed
22
  movf    H'064',f
23
  btfsc   H'FD8',2
24
  goto    if_57984_by
25
  ;a2nd   if_57984_by
26
if_57984_th: ; 0FE9
27

28
;; 040 :     target = leader
29
  movf    H'064',w
30
  movwf   H'002'
31
  movlw   H'02'
32
  addwf   H'062',w
33
  call    __indirection
34
  ;a2nd   __indirection
35
if_57984_by: ; 0FEF
36
  goto    if_57977_by
37
  ;a2nd   if_57977_by
38
if_57977_el: ; 0FF1
39

40
;; 046 :    if x < 10 then -- less than 10 ?
41
  movlw   H'0A'
42
  subwf   H'063',w
43
  btfsc   H'FD8',0
44
  goto    if_57997_el
45
  ;a2nd   if_57997_el
46
if_57997_th: ; 0FF6
47

48
;; 047 :    target = "0" + x -- send ASCII 0...9
49
  movf    H'063',w
50
  addlw   H'30'
51
  movwf   H'002'
52
  movlw   H'02'
53
  addwf   H'062',w
54
  call    __indirection
55
  ;a2nd   __indirection
56
  goto    if_57997_by
57
  ;a2nd   if_57997_by
58
if_57997_el: ; 0FFF
59

60
;; 049 :    target = "A" + x - 10 -- send ASCII A,B,C...
61
  movlw   H'0A'
62
  subwf   H'063',w
63
  addlw   H'41'
64
  movwf   H'002'
65
  movlw   H'02'
66
  addwf   H'062',w
67
  call    __indirection
68
  ;a2nd   __indirection
69
if_57997_by: ; 1007
70

71
;; 051 :    leader = "0"
72
  movlw   H'30'
73
  movwf   H'064'
74
if_57977_by: ; 1009
75
e_57957__print_base: ; 1009
76
  return

Ich versuch zu begreifen wie das funktioniert.
Da wird jedesmal das gleiche gemacht bevor die __indirection aufgerufen 
wird, also wollte ich den code bischen optimieren.Aber irgendwo muss es
noch was im weg sein.
1
  movlw   H'02'
2
  addwf   H'062',w
3
  call    __indirection
#2562711
Lesenswert?

Wenn du den Inhalt der variable "target" H'062' kennst, kannst du selbst 
die H'02' addieren und an Stelle der beiden Befehle
  movlw   H'Ergebnis' schreiben.
Ist aber nicht viel mit Optimierung.

Dein

__indirection
  goto  p_73038_generated_aget

kann nicht funkteonieren, da du den Inhalt von PCH und PCU nicht 
berücksichtigst. Diese müssen nämlich 0 sein.
Im O.Programm werden PCLATH und PCLATU gelöscht, der Inhalt von W mit 2 
multipliziert und mit  "movwf   PCL" wird PCLATH in PCH, PCLATU in PCU 
und W in PCL kopiert und bildet die neue Adresse <PC> wo das Programm 
weiterläuft.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren