Question: Write an assembler that reads the source code of an assembly program (for an imaginary machine) and displays the machine language for that program The
Write an assembler that reads the source code of an assembly program (for an imaginary machine) and displays the machine language for that program The following assembler instructions must be supported. Instruction opcode ren Length Format Example 0 add Ri, R2, R3 R3-R1 + R2 O sub R1, R2, R3 R3-R1 - R2 0 mult R1, R2, R3 R3-R1 R2 0 div Ri, R2, R3 IRRI R2 1 load Rl, addr (R71 RI memory value 1 laddr Ri, addr R71 RI address 1 store Rl addr R7] RI memory call addr push return addr on stack and jump to addr pop address from stack and jump to there 2 Sump addr (R7) jump to address 1 R1, addr (R7) lump to address only if RI is zero 4 1 R1,addr[R jump to address only if Riis neative push R1 push RI on stack 3 pop R1 pop stack into RI lpsw R1 load PSW into RI SpaWRI store Rl into PSW data 123 created a data word jums push pop D Machine language instructions have the following formats O: arithmetic opcode Reg 1 Reg 2 Reg 3 4 bits 4 bits 4 bits 4 bits 1: Load, store, conditional jump opcode Reg. index addir 4 bits 4 bits 4 bits 20 bits 2: call, jump opcode unused index 4 bits 4 bits 4 bits addir 20 bits 3.push, pop, Ipsw. spsw opcode Reg 4 bits4 bits more ct opcode unused 4 bits 4 bits S: data integer data value 32 bits A comment in the assembly program is indicated by an asterisk, **, in the first column of the source code. Labels must start in the first column. Your assembler does not have to detect every Write an assembler that reads the source code of an assembly program (for an imaginary machine) and displays the machine language for that program The following assembler instructions must be supported. Instruction opcode ren Length Format Example 0 add Ri, R2, R3 R3-R1 + R2 O sub R1, R2, R3 R3-R1 - R2 0 mult R1, R2, R3 R3-R1 R2 0 div Ri, R2, R3 IRRI R2 1 load Rl, addr (R71 RI memory value 1 laddr Ri, addr R71 RI address 1 store Rl addr R7] RI memory call addr push return addr on stack and jump to addr pop address from stack and jump to there 2 Sump addr (R7) jump to address 1 R1, addr (R7) lump to address only if RI is zero 4 1 R1,addr[R jump to address only if Riis neative push R1 push RI on stack 3 pop R1 pop stack into RI lpsw R1 load PSW into RI SpaWRI store Rl into PSW data 123 created a data word jums push pop D Machine language instructions have the following formats O: arithmetic opcode Reg 1 Reg 2 Reg 3 4 bits 4 bits 4 bits 4 bits 1: Load, store, conditional jump opcode Reg. index addir 4 bits 4 bits 4 bits 20 bits 2: call, jump opcode unused index 4 bits 4 bits 4 bits addir 20 bits 3.push, pop, Ipsw. spsw opcode Reg 4 bits4 bits more ct opcode unused 4 bits 4 bits S: data integer data value 32 bits A comment in the assembly program is indicated by an asterisk, **, in the first column of the source code. Labels must start in the first column. Your assembler does not have to detect every
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
