Skip to content

Commit b6c2983

Browse files
committed
Perlito5::X64::Assembler - more internal functions
1 parent 810d6f3 commit b6c2983

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src5/lib/Perlito5/X64/Assembler.pm

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,36 @@ sub emit {
2121
push @buffer, $_[0];
2222
}
2323

24+
25+
sub is_zero {
26+
return $_[0] == 0;
27+
}
28+
29+
sub is_int8 {
30+
return -128 <= $_[0] && $_[0] < 128;
31+
}
32+
33+
sub is_int16 {
34+
return -32768 <= $_[0] && $_[0] < 32768;
35+
}
36+
37+
sub is_uint8 {
38+
return 0 <= $_[0] && $_[0] < 256;
39+
}
40+
41+
sub is_uint16 {
42+
return 0 <= $_[0] && $_[0] < 65536;
43+
}
44+
45+
2446
#---
2547

48+
sub nop {
49+
emit(0x90);
50+
}
51+
2652
sub ret {
27-
my ( $self, $imm16 ) = @_;
53+
my ( $imm16 ) = @_;
2854
if ( !$imm16 ) {
2955
emit(0xC3);
3056
}

t5-x64/01_sanity.t

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ use warnings;
1212
use feature 'say';
1313
use Perlito5::X64::Assembler;
1414

15-
say "1..1";
16-
17-
my $asm = Perlito5::X64::Assembler->new();
15+
say "1..2";
1816

1917
{
2018
package Perlito5::X64::Assembler;
19+
my $out;
2120

2221
ret();
23-
my $out = to_hex();
24-
25-
print "not " if $out ne 'C3';
26-
say "ok # $out";
22+
$out = to_hex();
23+
print "not " if $out ne 'C3';
24+
say "ok # $out";
25+
ret(10);
26+
$out = to_hex();
27+
print "not " if $out ne 'C3 C2 0A 00';
28+
say "ok # $out";
2729
}
2830

0 commit comments

Comments
 (0)