Click to See Complete Forum and Search --> : Not your average question...
HarryW
Dec 5th, 2000, 11:16 PM
One reason this isn't your average C forum question is that it isn't really about C :)
This is closest really to assembler, so I've posted the thread there. I know you C programmer people tend to work in ASM quite often, and generally work at a lower level, so if you wouldn't mind, take a look would ya? Thanks :)
http://forums.vb-world.net/showthread.php?threadid=43228
HarryW
Dec 15th, 2000, 07:00 AM
In case anyone cares, this was my solution (couldn't get the simulator to work so I could test it) and I'm pretty sure it's right.
imul1 OPC=0x20 // Set OPC as a counter... OPC = 32
imul2 MAR=SP-1; rd // Read first operand (second word on the stack)
imul3 H=TOS // Operands are now in H and MDR, TOS freed to be accumulator
imul4 TOS=0 // Clear accumulator. One 0 just handled.
imul5 MDR=MDR; SRA1; if (notLSB) goto imul17 // Check for 00, else carry on for 10
imul6 TOS=TOS-H; SRA1 // 10 - subtract multiplicand, start the shift
imul7 MDR=MDR; RROT // Bitwise rotate on MDR, LSB has the next recode bit
imul8 OPC=OPC-1; if (Z) goto imul18 // Decrement the counter (OPC), if it's 0 then we've finished
imul9 MDR=MDR; SRA1; if (notLSB) goto imul14 // One 1 just handled, Check for 11/10 and skip one line if 10
imul10 TOS=TOS; SRA1; goto imul10 // 11 so start a shift then check for 10
imul11 TOS=TOS+H; SRA1 // 01 so add multiplicand then shift
imul12 MDR=MDR; RROT // Bitwise rotate on MDR, LSB has the next recode bit
imul13 OPC=OPC-1; if (Z) goto imul19 else goto imul8 // Decrement counter. Set JAM then set again if counter=zero
imul14 TOS=TOS; SRA1; goto imul15 // 00 so middle of string of 0s - keep shifting.
imul15 wr; goto imul20 // Write MDR to SP-1 (most significant word). Skip next line.
imul16 wr // Extra end-point, due to the way mic-1 conditional jumps work
imul17 MAR=SP // Prepare to write LSW to top of stack.
imul18 MDR=TOS; wr; goto Main1 // Write least significant word to top of stack. End instruction
That has to be the hardest piece of coursework I have ever had to do. Still, the lecturer said he would give people high marks (80%+) just for attempting this (I picked the hardest question ;) ).
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.