Skip to content

Commit c5b785c

Browse files
authored
Update README.md
1 parent 49f3457 commit c5b785c

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

README.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Any empty files, fully commented files, or files without `.s` extension will not
5858

5959
## Instruction Format Functions
6060

61-
This package also offers instruction format-specific functions for individual lines of assembly. The instruction types supported are R, I, S, SB, U, and UJ. The outputs to these are written to text or binary files or printed to console, depending on how the constructor was initialized. For the below examples, they are being outputted to binary files.
61+
This package also offers instruction format-specific functions for individual lines of assembly. The instruction types supported are R, I, S, SB, U, and UJ. The machine code is returned as a bitstring that can be printed to console. Check out the examples below for each instruction type:
6262

6363
### R_type()
6464

@@ -70,8 +70,10 @@ Here is an example of translating `add x0 s0 s1`
7070

7171
from riscv_assembler.convert import AssemblyConverter
7272

73-
cnv = AssemblyConverter() #output to binary
74-
cnv.R_type("add","x0","s0","s1") #convert the instruction
73+
cnv = AssemblyConverter()
74+
instr = cnv.R_type("add","x0","s0","s1") #convert the instruction
75+
76+
print(instr)
7577

7678
Note that the registers are being written as strings. The package maps them correctly to their respective binary values (ex. `s0` maps to `x8`).
7779

@@ -86,7 +88,9 @@ Here is an example of translating `addi x0 x0 32`
8688
from riscv_assembler.convert import AssemblyConverter
8789

8890
cnv = AssemblyConverter() #output to binary
89-
cnv.I_type("addi","x0","32","x0") #convert the instruction
91+
instr = cnv.I_type("addi","x0","32","x0") #convert the instruction
92+
93+
print(instr)
9094

9195
Note that the immediate is a string, not just a number. This was implemented this way for seamless integration with the convert() function, there is an easy workaround for using it on its own.
9296

@@ -101,7 +105,9 @@ Here is an example of translating `sw x0 0(sp)`
101105
from riscv_assembler.convert import AssemblyConverter
102106

103107
cnv = AssemblyConverter() #output to binary
104-
cnv.S_type("sw","x0","sp","0") #convert the instruction
108+
instr = cnv.S_type("sw","x0","sp","0") #convert the instruction
109+
110+
print(instr)
105111

106112
### SB_type()
107113

@@ -114,7 +120,9 @@ Here is an example of translating `beq x0 x1 loop`:
114120
from riscv_assembler.convert import AssemblyConverter
115121

116122
cnv = AssemblyConverter() #output to binary
117-
cnv.SB_type("beq","x0","x1","loop") #convert the instruction
123+
instr = cnv.SB_type("beq","x0","x1","loop") #convert the instruction
124+
125+
print(instr)
118126

119127
Note that the jump is written as a string, the appropriate instruction jump is calculated by the package.
120128

@@ -129,7 +137,9 @@ Here is an example of converting `lui x0 10`:
129137
from riscv_assembler.convert import AssemblyConverter
130138

131139
cnv = AssemblyConverter() #output to binary
132-
cnv.U_type("lui","x0","10") #convert the instruction
140+
instr = cnv.U_type("lui","x0","10") #convert the instruction
141+
142+
print(instr)
133143

134144
### UJ_type()
135145

@@ -142,7 +152,9 @@ Here is an example of converting `jal a0 func`:
142152
from riscv_assembler.convert import AssemblyConverter
143153

144154
cnv = AssemblyConverter() #output to binary
145-
cnv.UJ_type("jal","func","a0") #convert the instruction
155+
instr = cnv.UJ_type("jal","func","a0") #convert the instruction
156+
157+
print(instr)
146158

147159
## Helper Functions
148160

@@ -153,12 +165,13 @@ Here are a few functions that might be useful:
153165
This function simply prints the output type that has been initially selected. Example usage:
154166

155167
cnv = AssemblyConverter("bt") #initially write to binary and text file
156-
cnv.getOutputType()
168+
output_type = cnv.getOutputType()
169+
170+
print(output_type)
157171

158172
This will print to console:
159173

160-
Writing to binary file
161-
Writing to text file
174+
bt
162175

163176
### setOutputType()
164177

0 commit comments

Comments
 (0)