line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package CPU::Z80::Assembler::JumpOpcode; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
CPU::Z80::Assembler::JumpOpcode - Represents one jump assembly instruction to be |
10
|
|
|
|
|
|
|
computed at link time |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
15
|
|
|
|
|
|
|
|
16
|
31
|
|
|
31
|
|
1038
|
use strict; |
|
31
|
|
|
|
|
72
|
|
|
31
|
|
|
|
|
912
|
|
17
|
31
|
|
|
31
|
|
181
|
use warnings; |
|
31
|
|
|
|
|
63
|
|
|
31
|
|
|
|
|
1295
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '2.24'; |
20
|
|
|
|
|
|
|
|
21
|
31
|
|
|
31
|
|
609
|
use Asm::Preproc::Line; |
|
31
|
|
|
|
|
3343
|
|
|
31
|
|
|
|
|
195
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
3216
|
|
|
3216
|
1
|
9586
|
my($class, %args) = @_; |
25
|
|
|
|
|
|
|
bless [ |
26
|
|
|
|
|
|
|
$args{short_jump} || CPU::Z80::Assembler::Opcode->new(), |
27
|
|
|
|
|
|
|
# short jump opcode |
28
|
3216
|
|
66
|
|
|
17108
|
$args{long_jump} || CPU::Z80::Assembler::Opcode->new(), |
|
|
|
66
|
|
|
|
|
29
|
|
|
|
|
|
|
# long jump opcode |
30
|
|
|
|
|
|
|
], $class; |
31
|
|
|
|
|
|
|
} |
32
|
25705
|
50
|
|
25705
|
1
|
73766
|
sub short_jump { defined($_[1]) ? $_[0][0] = $_[1] : $_[0][0] } |
33
|
11987
|
50
|
|
11987
|
1
|
33620
|
sub long_jump { defined($_[1]) ? $_[0][1] = $_[1] : $_[0][1] } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# address and line : read from short_jump, write to short_jump and long_jump |
36
|
|
|
|
|
|
|
sub address { |
37
|
8826
|
|
|
8826
|
1
|
14368
|
my($self, $address) = @_; |
38
|
8826
|
100
|
|
|
|
15335
|
if (defined $address) { |
39
|
8823
|
|
|
|
|
13522
|
$self->short_jump->address($address); |
40
|
8823
|
|
|
|
|
14783
|
$self->long_jump->address($address); |
41
|
8823
|
|
|
|
|
16033
|
return $address; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
3
|
|
|
|
|
8
|
return $self->short_jump->address; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub line { |
49
|
63
|
|
|
63
|
1
|
2684
|
my($self, $line) = @_; |
50
|
63
|
100
|
|
|
|
149
|
if (defined $line) { |
51
|
1
|
|
|
|
|
3
|
$self->short_jump->line($line); |
52
|
1
|
|
|
|
|
10
|
$self->long_jump->line($line); |
53
|
1
|
|
|
|
|
3
|
return $line; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
62
|
|
|
|
|
165
|
return $self->short_jump->line; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
use CPU::Z80::Assembler::JumpOpcode; |
65
|
|
|
|
|
|
|
$opcode = CPU::Z80::Assembler::Opcode->new( |
66
|
|
|
|
|
|
|
short_jump => CPU::Z80::Assemble::Opcode->new( ... JR instr ...), |
67
|
|
|
|
|
|
|
long_jump => CPU::Z80::Assemble::Opcode->new( ... JP instr ...)); |
68
|
|
|
|
|
|
|
$opcode->address; |
69
|
|
|
|
|
|
|
$opcode->line; |
70
|
|
|
|
|
|
|
$dist = short_jump_dist($address, \%symbol_table); |
71
|
|
|
|
|
|
|
$bytes = $opcode->bytes($address, \%symbol_table); |
72
|
|
|
|
|
|
|
$size = $opcode->size; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This module defines the class that represents one jump instruction to be |
77
|
|
|
|
|
|
|
added to the object code. The object contains both the short jump form and |
78
|
|
|
|
|
|
|
the long jump form. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
During address allocation all short jumps that are out of range are replaced |
81
|
|
|
|
|
|
|
by long jumps. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 EXPORTS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Nothing. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 FUNCTIONS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 new |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Creates a new object. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 address |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Address where this opcode is loaded, computed at link time. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 short_jump |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Returns the L object representing the short jump. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 long_jump |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Returns the L object representing the long jump. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 line |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Get/set the line - text, file name and line number where the token was read. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 short_jump_dist |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Gets the short jump distance, in relation to the address of the next |
116
|
|
|
|
|
|
|
instruction. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Returns more than 127 or less than -128 if the short jump is out of range. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub short_jump_dist { |
125
|
3995
|
|
|
3995
|
1
|
7431
|
my($self, $address, $symbol_table) = @_; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# expr in a short jump is always second byte |
128
|
3995
|
|
|
|
|
8144
|
my $dist = $self->short_jump->child->[1]->evaluate($address, $symbol_table); |
129
|
3995
|
|
|
|
|
10441
|
return $dist; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 bytes |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$bytes = $opcode->bytes($address, \%symbol_table); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Computes all the expressions in the short jump and returns the bytes string |
139
|
|
|
|
|
|
|
with the result object code. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub bytes { |
146
|
2415
|
|
|
2415
|
1
|
4506
|
my($self, $address, $symbol_table) = @_; |
147
|
2415
|
|
|
|
|
4127
|
return $self->short_jump->bytes($address, $symbol_table); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 size |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$size = $opcode->size; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Return the number of bytes that the short_jump opcode will generate. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub size { |
163
|
8823
|
|
|
8823
|
1
|
15286
|
my($self) = @_; |
164
|
8823
|
|
|
|
|
14362
|
return $self->short_jump->size; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 BUGS and FEEDBACK |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
See L. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SEE ALSO |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L |
176
|
|
|
|
|
|
|
L |
177
|
|
|
|
|
|
|
L |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 AUTHORS, COPYRIGHT and LICENCE |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
See L. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
1; |
188
|
|
|
|
|
|
|
|