Skip to content

Commit

Permalink
transfer-lamports: Remove one instruction from ASM (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque authored Oct 3, 2024
1 parent c37ac49 commit 3c6400b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ lets the VM assume it worked.
| Rust | 464 |
| Zig | 186 |
| C | 103 |
| Assembly | 23 |
| Assembly | 22 |

This one starts to get interesting since it requires parsing the instruction
input. Since the assembly version knows exactly where to find everything, it can
Expand Down
4 changes: 1 addition & 3 deletions transfer-lamports/asm/main.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.text
.globl entrypoint
entrypoint:
ldxdw r2, [r1 + 0] # get number of accounts
Expand All @@ -8,14 +7,13 @@ entrypoint:
ldxdw r2, [r1 + 8 + 8 + 32 + 32] # get source lamports
ldxdw r3, [r1 + 8 + 8 + 32 + 32 + 8] # get account data size
mov64 r4, r1
add64 r4, 8 + 8 + 32 + 32 + 8 + 8 + 10240 # calculate end of account data
add64 r4, 8 + 8 + 32 + 32 + 8 + 8 + 10240 + 8 # calculate end of account data
add64 r4, r3
mov64 r5, r4 # check how much padding we need to add
and64 r5, 7 # clear high bits
jeq r5, 0, 1 # no low bits set, jump ahead
add64 r4, 8 # add 8 for truncation if needed
and64 r4, -8 # clear low bits
add64 r4, 8 # rent epoch
ldxb r5, [r4 + 0] # get second account
jne r5, 0xff, error # we don't allow duplicates
ldxdw r5, [r4 + 8 + 32 + 32] # get destination lamports
Expand Down

0 comments on commit 3c6400b

Please sign in to comment.