I have made a MARIE code that takes the input of 8 information bits and converts it to 12-bit hamming code. How to shorten this code? I am using the same XOR function for each parity bit with different value of each bit. I have first taken input for 8 bits in a loop and stored it at different addresses like an array. Then, I found the XOR of different parity bits (knowing the positions beforehand) and substituted the parity bits in the main information word (using the addresses of each position). Finally gave an output of the hamming code.
I have posted the code below:
'''
ORG 100
getInput, LoadI data
Skipcond 000
Input
Store temp
LoadI data
Skipcond 000
Load temp
StoreI data
Load data
Add one
Store data
Clear
Load size
Subt one
Store size
Skipcond 400
Jump getInput
Load dataTop
Add two
Store data
Load sizeMax
Store size
p1loop, LoadI data
Add p1
Store p1
Load data
Add two
Store data
Load size
Subt two
Store size
Skipcond 400
Jump p1loop
XOR, Load p1
Subt two
Store p1
Skipcond 000
Jump XOR
Add two
Store p1
Load dataTop
Store data
Load p1
StoreI data
Load dataTop
Add two
Store data
LoadI data
Store p2
Load sizeMax
Subt 2
Store size
p2loop, Load data
Add three
Store data
LoadI data
Add p2
Store p2
Load data
Add one
Store data
LoadI data
Add p2
Store p2
Load size
Subt four
Store size
Skipcond 400
Jump p2loop
XOR2, Load p2
Subt two
Store p2
Skipcond 000
Jump XOR2
Add two
Store p2
Load dataTop
Add one
Store data
Load p2
StoreI data
Load dataTop
Add four
Store data
Load three
Store size
p3loop, LoadI data
Add p3
Store p3
Load data
Add one
Store data
Load size
Subt one
Store size
Skipcond 400
Jump p3loop
Load dataTop
Add eleven
Store data
LoadI data
Add p3
Store p3
XOR3, Load p3
Subt two
Store p3
Skipcond 000
Jump XOR3
Add two
Store p3
Load dataTop
Add three
Store data
Load p3
StoreI data
Load dataTop
Add eight
Store data
Load eight
Store size
p4loop, LoadI data
Add p4
Store p4
Load data
Add one
Store data
Load size
Subt one
Store size
Skipcond 400
Jump p4loop
XOR4, Load p4
Subt two
Store p4
Skipcond 000
Jump XOR4
Add two
Store p4
Load dataTop
Add seven
Store data
Load p4
StoreI data
Load dataTop
Store data
Load sizeMax
Store size
ShowOutput, Clear
LoadI data
Output
Load data
Add one
Store data
Clear
Load size
Subt one
Store size
Skipcond 400
Jump ShowOutput
Halt
one, DEC 1
two, DEC 2
three, DEC 3
four, DEC 4
seven, DEC 7
eight, DEC 8
eleven, DEC 11
p1, DEC 0
p2, DEC 0
p3, DEC 0
p4, DEC 0
sizeMax, DEC 12
size, DEC 12
dataTop, HEX 1B0
temp, DEC 0
data, HEX 1B0
DEC -1
DEC -1
DEC 1
DEC -1
DEC 1
DEC 1
DEC 1
DEC -1
DEC 1
DEC 1
DEC 1
DEC 1
'''