From: Jacob Lifshay Date: Wed, 25 Nov 2020 07:41:07 +0000 (-0800) Subject: finish 16-bit compressed demo X-Git-Tag: convert-csv-opcode-to-binary~1662 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c7cea08a1cd341dbc5723ef09d9e90d254b5df90;p=libreriscv.git finish 16-bit compressed demo --- diff --git a/openpower/sv/16_bit_compressed/demo.mdwn b/openpower/sv/16_bit_compressed/demo.mdwn index aca34ef0a..50e83f0f2 100644 --- a/openpower/sv/16_bit_compressed/demo.mdwn +++ b/openpower/sv/16_bit_compressed/demo.mdwn @@ -61,7 +61,7 @@ Note that bit numbering goes from 0 to 31 in the prefix, then 0 to 31 in the suf | Field | Value | |-------------|------------------------------------------------| | Mnemonic | `paddi RT, RA, immed` | -| PO (0:5) | 14 | +| PO (0:5) | 1 | | (6:7) | 2 | | (8) | 0 | | (9:10) | // | @@ -85,33 +85,236 @@ Note that bit numbering goes from 0 to 31 in the prefix, then 0 to 31 in the suf | Mnemonic | PO (0:5) | placeholder (6:20) | XO (21:30) | placeholder (31:47) | Operation | |---------------|----------|--------------------|------------|---------------------|-------------| -| x.placeholder | 0 | placeholder | != 256 | placeholder | placeholder | +| x.placeholder | 0 | placeholder | 1 | placeholder | placeholder | ### Compressed Mode #### Compressed Mode 16-bit Instructions (New) -| Mnemonic | SCMT (0) | SOH (1:5) | SO (6:8) | SRT (9:11) | SRS (12:14) | SCM (15) | Operation | -|----------------|----------|-----------|----------|------------|-------------|----------|---------------------------------------------------------| -| c.add RT, RS | 0 | 1 | 0 | RT | RS | 0 | RT <- RT + RS | -| cs.add RT, RS | 0 | 1 | 0 | RT | RS | 1 | RT <- RT + RS
Swap to Compressed Mode | -| cst.add RT, RS | 1 | 1 | 0 | RT | RS | 1 | RT <- RT + RS
Swap to Compressed Mode Temporarily | - -## LE mode +| Mnemonic | SCMT (0) | SOH (1:5) | SO (6:8) | SRT (9:11) | SRS (12:14) | SCM (15) | Operation | +|----------------|----------|-----------|----------|------------|-------------|----------|-------------------------------------------------------| +| c.add RT, RS | 0 | 1 | 0 | RT | RS | 0 | RT <- RT + RS | +| cs.add RT, RS | 0 | 1 | 0 | RT | RS | 1 | RT <- RT + RS
Swap to Standard Mode | +| cst.add RT, RS | 1 | 1 | 0 | RT | RS | 1 | RT <- RT + RS
Swap to Standard Mode Temporarily | -TODO(programmerjake): finish +### Assembler bash script -| Address | Byte | Description | -|---------|------|-------------| -| 0x1000 | | | -| 0x1001 | | | +[[demo_assembler.sh]] -## BE mode +## Big-Endian Machine Code -TODO(programmerjake): finish +| Address | Byte | PC | Instruction | +|---------|------|--------|---------------------------| +| 0x1000 | 0x38 | 0x1000 | addi r3, r4, 5 | +| 0x1001 | 0x64 | 0x1000 | addi r3, r4, 5 | +| 0x1002 | 0x00 | 0x1000 | addi r3, r4, 5 | +| 0x1003 | 0x05 | 0x1000 | addi r3, r4, 5 | +| 0x1004 | 0x06 | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x1005 | 0x00 | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x1006 | 0xDE | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x1007 | 0xAD | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x1008 | 0x38 | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x1009 | 0x65 | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x100A | 0xBE | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x100B | 0xEF | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x100C | 0x00 | 0x100C | x.placeholder | +| 0x100D | 0x00 | 0x100C | x.placeholder | +| 0x100E | 0x00 | 0x100C | x.placeholder | +| 0x100F | 0x02 | 0x100C | x.placeholder | +| 0x1010 | 0x00 | 0x100C | x.placeholder | +| 0x1011 | 0x00 | 0x100C | x.placeholder | +| 0x1012 | 0x38 | 0x1012 | addi r3, r4, 5 | +| 0x1013 | 0x64 | 0x1012 | addi r3, r4, 5 | +| 0x1014 | 0x00 | 0x1012 | addi r3, r4, 5 | +| 0x1015 | 0x05 | 0x1012 | addi r3, r4, 5 | +| 0x1016 | 0x06 | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x1017 | 0x00 | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x1018 | 0x89 | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x1019 | 0xAB | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x101A | 0x38 | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x101B | 0x65 | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x101C | 0xCD | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x101D | 0xEF | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x101E | 0x00 | 0x101E | x.placeholder | +| 0x101F | 0x00 | 0x101E | x.placeholder | +| 0x1020 | 0x00 | 0x101E | x.placeholder | +| 0x1021 | 0x02 | 0x101E | x.placeholder | +| 0x1022 | 0x00 | 0x101E | x.placeholder | +| 0x1023 | 0x00 | 0x101E | x.placeholder | +| 0x1024 | 0x14 | 0x1024 | h.add r3, r4 | +| 0x1025 | 0x02 | 0x1024 | h.add r3, r4 | +| 0x1026 | 0x38 | 0x1026 | addi r3, r6, 7 | +| 0x1027 | 0x66 | 0x1026 | addi r3, r6, 7 | +| 0x1028 | 0x00 | 0x1026 | addi r3, r6, 7 | +| 0x1029 | 0x07 | 0x1026 | addi r3, r6, 7 | +| 0x102A | 0x14 | 0x102A | hs.add r3, r31 | +| 0x102B | 0x0F | 0x102A | hs.add r3, r31 | +| 0x102C | 0x04 | 0x102C | c.add r3, r30 | +| 0x102D | 0x0C | 0x102C | c.add r3, r30 | +| 0x102E | 0x84 | 0x102E | cst.add r3, r29 | +| 0x102F | 0x0B | 0x102E | cst.add r3, r29 | +| 0x1030 | 0x06 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1031 | 0x00 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1032 | 0x12 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1033 | 0x34 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1034 | 0x38 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1035 | 0x7F | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1036 | 0x56 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1037 | 0x78 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1038 | 0x04 | 0x1038 | c.add r3, r5 | +| 0x1039 | 0x04 | 0x1038 | c.add r3, r5 | +| 0x103A | 0x04 | 0x103A | c.add r3, r3 | +| 0x103B | 0x00 | 0x103A | c.add r3, r3 | +| 0x103C | 0x04 | 0x103C | cs.add r3, r6 | +| 0x103D | 0x07 | 0x103C | cs.add r3, r6 | +| 0x103E | 0x38 | 0x103E | addi r3, r3, 0x23 | +| 0x103F | 0x63 | 0x103E | addi r3, r3, 0x23 | +| 0x1040 | 0x00 | 0x103E | addi r3, r3, 0x23 | +| 0x1041 | 0x23 | 0x103E | addi r3, r3, 0x23 | +| 0x1042 | 0x38 | 0x1042 | addi r3, r10, 0xA | +| 0x1043 | 0x6A | 0x1042 | addi r3, r10, 0xA | +| 0x1044 | 0x00 | 0x1042 | addi r3, r10, 0xA | +| 0x1045 | 0x0A | 0x1042 | addi r3, r10, 0xA | +| 0x1046 | 0x14 | 0x1046 | hs.add r3, r5 | +| 0x1047 | 0x05 | 0x1046 | hs.add r3, r5 | +| 0x1048 | 0x84 | 0x1048 | cst.add r3, r4 | +| 0x1049 | 0x03 | 0x1048 | cst.add r3, r4 | +| 0x104A | 0x14 | 0x104A | hs.add r3, r6 | +| 0x104B | 0x07 | 0x104A | hs.add r3, r6 | +| 0x104C | 0x84 | 0x104C | cst.add r3, r28 | +| 0x104D | 0x09 | 0x104C | cst.add r3, r28 | +| 0x104E | 0x14 | 0x104E | h.add r3, r29 | +| 0x104F | 0x0A | 0x104E | h.add r3, r29 | +| 0x1050 | 0x84 | 0x1050 | cst.add r3, r30 | +| 0x1051 | 0x0D | 0x1050 | cst.add r3, r30 | +| 0x1052 | 0x00 | 0x1052 | x.placeholder | +| 0x1053 | 0x00 | 0x1052 | x.placeholder | +| 0x1054 | 0x00 | 0x1052 | x.placeholder | +| 0x1055 | 0x02 | 0x1052 | x.placeholder | +| 0x1056 | 0x00 | 0x1052 | x.placeholder | +| 0x1057 | 0x00 | 0x1052 | x.placeholder | +| 0x1058 | 0x84 | 0x1058 | cst.add r3, r31 | +| 0x1059 | 0x0F | 0x1058 | cst.add r3, r31 | +| 0x105A | 0x38 | 0x105A | addi r3, r15, 0xF | +| 0x105B | 0x6F | 0x105A | addi r3, r15, 0xF | +| 0x105C | 0x00 | 0x105A | addi r3, r15, 0xF | +| 0x105D | 0x0F | 0x105A | addi r3, r15, 0xF | +| 0x105E | 0x04 | 0x105E | cs.add r3, r4 | +| 0x105F | 0x03 | 0x105E | cs.add r3, r4 | +| 0x1060 | 0x38 | 0x1060 | addi r3, r10, 0xF | +| 0x1061 | 0x6A | 0x1060 | addi r3, r10, 0xF | +| 0x1062 | 0x00 | 0x1060 | addi r3, r10, 0xF | +| 0x1063 | 0x0F | 0x1060 | addi r3, r10, 0xF | +| 0x1064 | 0x38 | 0x1064 | addi r3, r11, 0xF | +| 0x1065 | 0x6B | 0x1064 | addi r3, r11, 0xF | +| 0x1066 | 0x00 | 0x1064 | addi r3, r11, 0xF | +| 0x1067 | 0x0F | 0x1064 | addi r3, r11, 0xF | -| Address | Byte | Description | -|---------|------|-------------| -| 0x1000 | | | -| 0x1001 | | | +## Little-Endian Machine Code +| Address | Byte | PC | Instruction | +|---------|------|--------|---------------------------| +| 0x1000 | 0x05 | 0x1000 | addi r3, r4, 5 | +| 0x1001 | 0x00 | 0x1000 | addi r3, r4, 5 | +| 0x1002 | 0x64 | 0x1000 | addi r3, r4, 5 | +| 0x1003 | 0x38 | 0x1000 | addi r3, r4, 5 | +| 0x1004 | 0xAD | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x1005 | 0xDE | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x1006 | 0x00 | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x1007 | 0x06 | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x1008 | 0xEF | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x1009 | 0xBE | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x100A | 0x65 | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x100B | 0x38 | 0x1004 | paddi r3, r5, 0xDEADBEEF | +| 0x100C | 0x02 | 0x100C | x.placeholder | +| 0x100D | 0x00 | 0x100C | x.placeholder | +| 0x100E | 0x00 | 0x100C | x.placeholder | +| 0x100F | 0x00 | 0x100C | x.placeholder | +| 0x1010 | 0x64 | 0x1012 | addi r3, r4, 5 | +| 0x1011 | 0x38 | 0x1012 | addi r3, r4, 5 | +| 0x1012 | 0x00 | 0x100C | x.placeholder | +| 0x1013 | 0x00 | 0x100C | x.placeholder | +| 0x1014 | 0x00 | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x1015 | 0x06 | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x1016 | 0x05 | 0x1012 | addi r3, r4, 5 | +| 0x1017 | 0x00 | 0x1012 | addi r3, r4, 5 | +| 0x1018 | 0x65 | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x1019 | 0x38 | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x101A | 0xAB | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x101B | 0x89 | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x101C | 0x00 | 0x101E | x.placeholder | +| 0x101D | 0x00 | 0x101E | x.placeholder | +| 0x101E | 0xEF | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x101F | 0xCD | 0x1016 | paddi r3, r5, 0x89ABCDEF | +| 0x1020 | 0x00 | 0x101E | x.placeholder | +| 0x1021 | 0x00 | 0x101E | x.placeholder | +| 0x1022 | 0x02 | 0x101E | x.placeholder | +| 0x1023 | 0x00 | 0x101E | x.placeholder | +| 0x1024 | 0x66 | 0x1026 | addi r3, r6, 7 | +| 0x1025 | 0x38 | 0x1026 | addi r3, r6, 7 | +| 0x1026 | 0x02 | 0x1024 | h.add r3, r4 | +| 0x1027 | 0x14 | 0x1024 | h.add r3, r4 | +| 0x1028 | 0x0F | 0x102A | hs.add r3, r31 | +| 0x1029 | 0x14 | 0x102A | hs.add r3, r31 | +| 0x102A | 0x07 | 0x1026 | addi r3, r6, 7 | +| 0x102B | 0x00 | 0x1026 | addi r3, r6, 7 | +| 0x102C | 0x0B | 0x102E | cst.add r3, r29 | +| 0x102D | 0x84 | 0x102E | cst.add r3, r29 | +| 0x102E | 0x0C | 0x102C | c.add r3, r30 | +| 0x102F | 0x04 | 0x102C | c.add r3, r30 | +| 0x1030 | 0x34 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1031 | 0x12 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1032 | 0x00 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1033 | 0x06 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1034 | 0x78 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1035 | 0x56 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1036 | 0x7F | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1037 | 0x38 | 0x1030 | paddi r3, r31, 0x12345678 | +| 0x1038 | 0x00 | 0x103A | c.add r3, r3 | +| 0x1039 | 0x04 | 0x103A | c.add r3, r3 | +| 0x103A | 0x04 | 0x1038 | c.add r3, r5 | +| 0x103B | 0x04 | 0x1038 | c.add r3, r5 | +| 0x103C | 0x63 | 0x103E | addi r3, r3, 0x23 | +| 0x103D | 0x38 | 0x103E | addi r3, r3, 0x23 | +| 0x103E | 0x07 | 0x103C | cs.add r3, r6 | +| 0x103F | 0x04 | 0x103C | cs.add r3, r6 | +| 0x1040 | 0x6A | 0x1042 | addi r3, r10, 0xA | +| 0x1041 | 0x38 | 0x1042 | addi r3, r10, 0xA | +| 0x1042 | 0x23 | 0x103E | addi r3, r3, 0x23 | +| 0x1043 | 0x00 | 0x103E | addi r3, r3, 0x23 | +| 0x1044 | 0x05 | 0x1046 | hs.add r3, r5 | +| 0x1045 | 0x14 | 0x1046 | hs.add r3, r5 | +| 0x1046 | 0x0A | 0x1042 | addi r3, r10, 0xA | +| 0x1047 | 0x00 | 0x1042 | addi r3, r10, 0xA | +| 0x1048 | 0x07 | 0x104A | hs.add r3, r6 | +| 0x1049 | 0x14 | 0x104A | hs.add r3, r6 | +| 0x104A | 0x03 | 0x1048 | cst.add r3, r4 | +| 0x104B | 0x84 | 0x1048 | cst.add r3, r4 | +| 0x104C | 0x0A | 0x104E | h.add r3, r29 | +| 0x104D | 0x14 | 0x104E | h.add r3, r29 | +| 0x104E | 0x09 | 0x104C | cst.add r3, r28 | +| 0x104F | 0x84 | 0x104C | cst.add r3, r28 | +| 0x1050 | 0x00 | 0x1052 | x.placeholder | +| 0x1051 | 0x00 | 0x1052 | x.placeholder | +| 0x1052 | 0x0D | 0x1050 | cst.add r3, r30 | +| 0x1053 | 0x84 | 0x1050 | cst.add r3, r30 | +| 0x1054 | 0x00 | 0x1052 | x.placeholder | +| 0x1055 | 0x00 | 0x1052 | x.placeholder | +| 0x1056 | 0x02 | 0x1052 | x.placeholder | +| 0x1057 | 0x00 | 0x1052 | x.placeholder | +| 0x1058 | 0x6F | 0x105A | addi r3, r15, 0xF | +| 0x1059 | 0x38 | 0x105A | addi r3, r15, 0xF | +| 0x105A | 0x0F | 0x1058 | cst.add r3, r31 | +| 0x105B | 0x84 | 0x1058 | cst.add r3, r31 | +| 0x105C | 0x03 | 0x105E | cs.add r3, r4 | +| 0x105D | 0x04 | 0x105E | cs.add r3, r4 | +| 0x105E | 0x0F | 0x105A | addi r3, r15, 0xF | +| 0x105F | 0x00 | 0x105A | addi r3, r15, 0xF | +| 0x1060 | 0x0F | 0x1060 | addi r3, r10, 0xF | +| 0x1061 | 0x00 | 0x1060 | addi r3, r10, 0xF | +| 0x1062 | 0x6A | 0x1060 | addi r3, r10, 0xF | +| 0x1063 | 0x38 | 0x1060 | addi r3, r10, 0xF | +| 0x1064 | 0x0F | 0x1064 | addi r3, r11, 0xF | +| 0x1065 | 0x00 | 0x1064 | addi r3, r11, 0xF | +| 0x1066 | 0x6B | 0x1064 | addi r3, r11, 0xF | +| 0x1067 | 0x38 | 0x1064 | addi r3, r11, 0xF | \ No newline at end of file diff --git a/openpower/sv/16_bit_compressed/demo_assembler.sh b/openpower/sv/16_bit_compressed/demo_assembler.sh new file mode 100755 index 000000000..9cf2bcdfa --- /dev/null +++ b/openpower/sv/16_bit_compressed/demo_assembler.sh @@ -0,0 +1,136 @@ +#!/bin/bash +mapfile -t lines <<'EOF' +addi r3, r4, 5 +paddi r3, r5, 0xDEADBEEF +x.placeholder +addi r3, r4, 5 +paddi r3, r5, 0x89ABCDEF +x.placeholder +h.add r3, r4 +addi r3, r6, 7 +hs.add r3, r31 +c.add r3, r30 +cst.add r3, r29 +paddi r3, r31, 0x12345678 +c.add r3, r5 +c.add r3, r3 +cs.add r3, r6 +addi r3, r3, 0x23 +addi r3, r10, 0xA +hs.add r3, r5 +cst.add r3, r4 +hs.add r3, r6 +cst.add r3, r28 +h.add r3, r29 +cst.add r3, r30 +x.placeholder +cst.add r3, r31 +addi r3, r15, 0xF +cs.add r3, r4 +addi r3, r10, 0xF +addi r3, r11, 0xF +EOF + +declare -a small_regs +small_regs[3]=0 +small_regs[4]=1 +small_regs[5]=2 +small_regs[6]=3 +small_regs[28]=4 +small_regs[29]=5 +small_regs[30]=6 +small_regs[31]=7 +pc=0x1000 +initial_pc=$((pc)) +bytes=() +function out_byte_text() { + local s + printf -v s '| %4s | %6s | %-30s |' "$1" "$2" "$3" + bytes+=("$s") +} +function out_byte() { + local a b + printf -v a '0x%02X' $(($1)) + printf -v b '0x%04X' $((pc)) + out_byte_text "$a" "$b" "$line" +} +function out_16() { + out_byte $(($1 >> 8)) + out_byte $(($1 & 0xFF)) +} +function out_32() { + out_16 $(($1 >> 16)) + out_16 $(($1 & 0xFFFF)) +} +for line in "${lines[@]}"; do + if [[ "$line" =~ ^([a-z0-9.]+)(' '+'r'?([0-9]+)','' '*'r'?([0-9]+)(','' '*([0-9xA-Fa-f]+))?)?$ ]]; then + opcode="${BASH_REMATCH[1]}" + arg1="${BASH_REMATCH[3]}" + arg2="${BASH_REMATCH[4]}" + arg3="${BASH_REMATCH[6]}" + else + echo "invalid line: $line" + exit 1 + fi + arg1s="${small_regs[arg1]}" + arg2s="${small_regs[arg2]}" + case "$opcode" in + addi) + out_32 $((14 << 31 - 5 | arg1 << 31 - 10 | arg2 << 31 - 15 | arg3 & 0xFFFF)) + ((pc += 4)) + ;; + paddi) + out_32 $((1 << 31 - 5 | 2 << 31 - 7 | (arg3 >> 16) & 0x3FFFF)) + out_32 $((14 << 31 - 5 | arg1 << 31 - 10 | arg2 << 31 - 15 | arg3 & 0xFFFF)) + ((pc += 8)) + ;; + x.placeholder) + out_32 $((0 << 31 - 5 | 1 << 31 - 30)) + out_16 0 + ((pc += 6)) + ;; + h.add) + out_16 $((5 << 15 - 5 | arg1s << 15 - 11 | arg2s << 15 - 14)) + ((pc += 2)) + ;; + hs.add) + out_16 $((5 << 15 - 5 | arg1s << 15 - 11 | arg2s << 15 - 14 | 1)) + ((pc += 2)) + ;; + c.add) + out_16 $((1 << 15 - 5 | arg1s << 15 - 11 | arg2s << 15 - 14)) + ((pc += 2)) + ;; + cs.add) + out_16 $((1 << 15 - 5 | arg1s << 15 - 11 | arg2s << 15 - 14 | 1)) + ((pc += 2)) + ;; + cst.add) + out_16 $((1 << 15 | 1 << 15 - 5 | arg1s << 15 - 11 | arg2s << 15 - 14 | 1)) + ((pc += 2)) + ;; + *) + echo "invalid opcode: $opcode" + echo "line: $line" + exit 1 + ;; + esac +done +while ((${#bytes[@]} % 4 != 0)); do + out_byte_text "" "" "" +done +function write() { + local i + local endian="$1" + local endian_bits=$(($2)) + echo "## $endian Machine Code" + echo + echo "| Address | Byte | PC | Instruction |" + echo "|---------|------|--------|--------------------------------|" + for((i=0;i<${#bytes[@]};i++)); do + printf "| 0x%04X %s\n" $((i + initial_pc)) "${bytes[i ^ endian_bits]}" + done +} +write "Big-Endian" 0 +echo +write "Little-Endian" 3