Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5::X64::Assembler - more internal functions
  • Loading branch information
fglock committed Mar 24, 2013
1 parent 810d6f3 commit b6c2983
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
28 changes: 27 additions & 1 deletion src5/lib/Perlito5/X64/Assembler.pm
Expand Up @@ -21,10 +21,36 @@ sub emit {
push @buffer, $_[0];
}


sub is_zero {
return $_[0] == 0;
}

sub is_int8 {
return -128 <= $_[0] && $_[0] < 128;
}

sub is_int16 {
return -32768 <= $_[0] && $_[0] < 32768;
}

sub is_uint8 {
return 0 <= $_[0] && $_[0] < 256;
}

sub is_uint16 {
return 0 <= $_[0] && $_[0] < 65536;
}


#---

sub nop {
emit(0x90);
}

sub ret {
my ( $self, $imm16 ) = @_;
my ( $imm16 ) = @_;
if ( !$imm16 ) {
emit(0xC3);
}
Expand Down
16 changes: 9 additions & 7 deletions t5-x64/01_sanity.t
Expand Up @@ -12,17 +12,19 @@ use warnings;
use feature 'say';
use Perlito5::X64::Assembler;

say "1..1";

my $asm = Perlito5::X64::Assembler->new();
say "1..2";

{
package Perlito5::X64::Assembler;
my $out;

ret();
my $out = to_hex();

print "not " if $out ne 'C3';
say "ok # $out";
$out = to_hex();
print "not " if $out ne 'C3';
say "ok # $out";
ret(10);
$out = to_hex();
print "not " if $out ne 'C3 C2 0A 00';
say "ok # $out";
}

0 comments on commit b6c2983

Please sign in to comment.