Skip to content

Commit 0bc0309

Browse files
committed
Add instruction for 'revb' - reverse bytes in a word.
1 parent d64c387 commit 0bc0309

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

aha.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "simulator.h"
55

66
#ifndef NARGS
7-
#define NARGS 1 // Number of args in userfun, 1 or 2.
7+
#define NARGS 1 // Number of args in userfun, 1, 2 or 3.
88
#endif
99

1010
const int debug = 0; // 0 or 1; debugging printouts if 1.

machine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static const isa_t isa[] = {
3333
// {seleq, 3, 0, {RX, 0, 0}, "seleq", "seleq(", ", " }, // Select if = 0.
3434
// {sellt, 3, 0, {RX, 0, 0}, "sellt", "sellt(", ", " }, // Select if < 0.
3535
// {selle, 3, 0, {RX, 0, 0}, "selle", "selle(", ", " }, // Select if <= 0.
36+
{revb, 1, 0, {RX, 0, 0}, "revb", "revb(", "" }, // Byte reversal.
3637
};
3738

3839
#endif /* MACHINE_H */

simulator.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ int rev(int xi, int y, int z) {
4343
return x;
4444
}
4545

46+
int revb(int xi, int y, int z) {
47+
unsigned x = xi;
48+
return ((x & 0x000000FF) << 24) | ((x >> 24) & 0x000000FF) |
49+
((x & 0x0000FF00) << 8) | ((x >> 8) & 0x0000FF00);
50+
}
51+
52+
4653
int add (int x, int y, int z) {return x + y;}
4754
int sub (int x, int y, int z) {return x - y;}
4855
int rsb (int x, int y, int z) {return y - x;}

simulator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
typedef int (simproc)(int, int, int);
77

8-
simproc neg, _not, pop, nlz, rev, add, sub, rsb, mul, _div, _divu, _mod,
9-
_modu, _and, _or, _xor, _bic, rotl, rotr, shl, shr, shrs, cmpeq,
10-
cmplt, cmpltu, seleq, sellt, selle;
8+
simproc neg, _not, pop, nlz, rev, revb, add, sub, rsb, mul, _div, _divu,
9+
_mod, _modu, _and, _or, _xor, _bic, rotl, rotr, shl, shr, shrs,
10+
cmpeq, cmplt, cmpltu, seleq, sellt, selle;
1111

1212
#endif /* SIMULATOR_H */
1313

0 commit comments

Comments
 (0)