Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
partial hlorenzi#115: increment address within asm blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmett81 authored and hlorenzi committed Oct 18, 2021
1 parent 0c96b6d commit 1ecb2d5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/asm/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,10 @@ impl State
fileserver: &dyn util::FileServer)
-> Result<expr::Value, ()>
{
// Clone the context in order to advance the logical address
// between instructions.
let mut inner_ctx = ctx.clone();

let mut result = util::BigInt::new(0, Some(0));

let mut parser = syntax::Parser::new(Some(info.report.clone()), info.tokens);
Expand Down Expand Up @@ -1386,7 +1390,7 @@ impl State
let matches = asm::parser::match_rule_invocation(
&self,
subparser,
ctx.clone(),
inner_ctx.clone(),
fileserver,
info.report.clone())?;

Expand Down Expand Up @@ -1440,6 +1444,8 @@ impl State
&bigint,
(size, 0));
}

inner_ctx.bit_offset += size;
}

parser.expect_linebreak()?;
Expand Down
21 changes: 21 additions & 0 deletions tests/issue115/1.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#bits 4

#ruledef
{
jmp {addr: u4} => addr

asmjmp {addr: u4} => asm
{
jmp addr
}

op => asm
{
jmp $
asmjmp $
jmp $
}
}

op ; = 0x012
op ; = 0x345
27 changes: 27 additions & 0 deletions tests/issue115/2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#bits 4

#ruledef
{
jmp {addr: u4} => addr

asmjmp {addr: u4} => asm
{
jmp addr
jmp $
}

op => asm
{
jmp $
asmjmp $
jmp $
}
}

op ; = 0x0123
#d asm
{
op ; = 0x4567
op ; = 0x89ab
}
op ; = 0xcdef

0 comments on commit 1ecb2d5

Please sign in to comment.