Using the Stack_8Shell code under Files in Moodle, put in the code to do the instructions for: AND, TAD, ISZ, DCA, JMS,

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Using the Stack_8Shell code under Files in Moodle, put in the code to do the instructions for: AND, TAD, ISZ, DCA, JMS,

Post by answerhappygod »

Using the Stack_8Shell code under Files in Moodle, put in the
code to do the instructions for: AND, TAD, ISZ, DCA, JMS, JMP, CLL,
CMA, CML, IAC, SMA, SZA, and SNL. Look in the stack_8.cpp file for
the comment starting with “// put in code”.
The stack_8.cpp file uses the stack_8 object of “stk8” as the
cpu. The cpu has two main functions of “cu” for control and
reading/writing from/to memory and the “alu” for doing operations.
To see what the operations are, look at the stack_8.h file – they
are listed as enum types – along with a TON of constants. But the
alu operations are actually implemented via C++ overloaded
operators. The registers are listed as reg8 class types also and
those use the overloaded operators to do the alu operations. Those
overloaded operators are spread between the
The cu function is straight forward and its form is:
void cu(CU_OP);
The CU_OP are the CU operations allowed (enumerated) that are
listed in stack.h
The alu overloaded operators are:
reg3 = reg1 + reg2 // adds reg1 to reg2 and places the answer
into reg3
reg3 = reg1 & reg2 // ands reg1 to reg2 and places the
answer into reg3
reg3 = reg1 | reg2 // ors reg1 to reg2 and places the
answer into reg3
reg3 = reg1 ^ reg2 // xors reg1 to reg2 and places the
answer into reg3
reg2 = reg1 << link // rol reg1and put in a 1 rightmost
bit if link true, else 0,
// put answer into reg2
reg2 = reg1 >> link // ror reg1and put in a 1 leftmost bit
if link true, else 0,
// put answer into reg2
reg1 *
reg2
// multiply reg1 and reg2,
// put top 12 bits into reg1 and bottom 12 bits into reg2
reg2 =
~reg1
// complement bits in reg1 and set reg2 to them
reg2 =
!reg1
// swap top 6 bits with lower 6 bits in reg1
//
and set reg2 to them
reg2 =
*reg1
// sign extend reg1 and put answer into reg2
reg2 =
reg1
// copy reg1 into reg2
reg =
1234
// copy word value into reg
w =
+reg
// get contents of reg and put into word w
The “word” is just a short int. You probably won’t use all of
the overloaded operators but they are listed for completeness.
The registers defined for you to use are: pc, ir, opcode, ac,
link, ma, md, stack, temp, iminus1, ione, imask7, imask6, izero,
intrpt, device, switches, hlt and mq
You definitely will NOT use all of those registers.
The pc, ir, ac, link, ma, md and stack are familiar with the
stack 8. The temp is just that, meant for temporary storage. The
iminus1, ione, izero are values of -1, 1, and 0 for you to use. The
imask7 and imask6 are used by the support routines to take apart
the current instruction. The device register is for I/O and the
intrpt is for future implementation of interrupts in the emulator.
The switches, hlt and mq are miscellaneous registers. You can
access those register directly.
Example, add one to the ac:
ac = ac + ione;
And you have incremented the ac register!
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply