Question: i need help implementing the logic for this program void lmsm _ cap _ value ( int * val ) { / / TODO -
i need help implementing the logic for this program
void lmsmcapvalueint valTODO implement capping the value pointed to by this pointer between and if val val ; Cap the value at else if val val ; Cap the value at int lmsmhastwovaluesonstacklmsm ourlittlemachineTODO return
Instruction Implementation
void lmsmijallmsm ourlittlemachine
void lmsmiretlmsm ourlittlemachine
void lmsmipushlmsm ourlittlemachine
void lmsmipoplmsm ourlittlemachine
void lmsmiduplmsm ourlittlemachine
void lmsmidroplmsm ourlittlemachine
void lmsmiswaplmsm ourlittlemachine
void lmsmisaddlmsm ourlittlemachine
void lmsmissublmsm ourlittlemachine
void lmsmismaxlmsm ourlittlemachine
void lmsmisminlmsm ourlittlemachine
void lmsmismullmsm ourlittlemachine
void lmsmisdivlmsm ourlittlemachine
void lmsmioutlmsm ourlittlemachine
TODO, append the current accumulator to the outputbuffer in the LMSM
void lmsmiinplmsm ourlittlemachine
TODO read a value from the command line and store it as an int in the accumulator
void lmsmiloadlmsm ourlittlemachine, int location
void lmsmiaddlmsm ourlittlemachine, int location
ourlittlemachineaccumulator ourlittlemachinememorylocation;
void lmsmisublmsm ourlittlemachine, int location
ourlittlemachineaccumulator ourlittlemachinememorylocation;
void lmsmiloadimmediatelmsm ourlittlemachine, int value
void lmsmistorelmsm ourlittlemachine, int location
void lmsmihaltlmsm ourlittlemachine
void lmsmibranchunconditionallmsm ourlittlemachine, int location
void lmsmibranchifzerolmsm ourlittlemachine, int location
void lmsmibranchifpositivelmsm ourlittlemachine, int location
void lmsmsteplmsm ourlittlemachine
TODO : if the machine is not halted, we need to read the instruction in the memory slot
pointed to by the program counter, bump the program counter then execute
the instruction
if ourlittlemachinestatus STATUSHALTED
int nextinstruction ourlittlemachinememoryourlittlemachineprogramcounter;
ourlittlemachineprogramcounter;
ourlittlemachinecurrentinstruction nextinstruction;
int instruction ourlittlemachinecurrentinstruction;
lmsmexecinstructionourlittlemachine, instruction;
LMSM Implementation
void lmsmexecinstructionlmsm ourlittlemachine, int instruction
TODO dispatch the rest of the instruction set and implement
the instructions above
if instruction
lmsmihaltourlittlemachine;
else if instruction && instruction
lmsmiaddourlittlemachine, instruction ;
else if instruction && instruction
lmsmisubourlittlemachine, instruction ;
else if instruction && instruction
lmsmibranchunconditionalourlittlemachine, instruction ;
else if instruction
lmsmipushourlittlemachine;
else if instruction
lmsmisaddourlittlemachine;
else
ourlittlemachineerrorcode ERRORUNKNOWNINSTRUCTION;
ourlittlemachinestatus STATUSHALTED;
lmsmcapvalue&ourlittlemachineaccumulator;
void lmsmloadlmsm ourlittlemachine, int program int length
for int i ; i length; i
ourlittlemachinememoryi programi;
void lmsminitlmsm themachine
themachineaccumulator ;
themachinestatus STATUSREADY;
themachineerrorcode ERRORNONE;
themachineprogramcounter ;
themachinecurrentinstruction ;
themachinestackpointer TOPOF
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
