Problem with Little Man Computer

Discussion in 'Software' started by Mo123, Jun 14, 2012.

  1. Mo123

    Mo123 Private E-2

    Hi,

    Why when I put in this program in man computer does it not stop and keep on looping? Is there a solution for this?

    INP
    STA DEC
    INP
    LOOP SUB DEC
    OUT
    BRZ
    QUIT
    BRA LOOP
    QUIT HLT
    DEC HAT



    Thanks,
    Mo
     
  2. PC-XT

    PC-XT Master Sergeant

    Here's my breakdown: (By hand.)
    00: 901 INP //get input from the INBOX, and put it in the accumulator (calculator)
    01: 308 STA DEC //store accumulator in DEC
    02: 901 INP //get another input from INBOX to the accumulator
    03: 208 SUB DEC, label LOOP //subtract DEC from accumulator
    04: 902 OUT //write accumulator to OUTBOX
    05: 707 BRZ QUIT //If accumulator is 000, branch to QUIT
    06: 603 BRA LOOP //branch to LOOP to continue subtracting DEC from the accumulator, outputting the result, until 000 is reached
    07: 000 HLT, label QUIT//end
    08: ??? DAT, Label DEC//I don't know HAT, assuming you meant DAT

    According to the code, if the accumulator never reaches 000, it will loop forever.

    Try input 000, 000. That should quit immediately after outputting 000.

    If you use input 000, 001, it will never end, because the accumulator will always be 001.

    Note: If the accumulator goes negative, results are undefined, as it is an underflow. Some implementations may use 2's complement, sign and magnitute, or some other format to store negative numbers as positive ones. The only way to tell if it's negative in basic LMC is with the BRP instruction, but the accumulator may not even remember that it's a negative number when performing the next ADD or SUB instruction in some implementations, taking the positive representation of the negative number as a literal positive number.

    It's only compiling wrong if it outputs 000 but doesn't stop. If that's the case, the following may be the reason:

    Mailbox 05 was split between two lines, which confused me at first, and may confuse some compilers, too.

    I assume HAT is a typo, but even if mailbox 08 gets compiled wrong, it likely won't matter because it's after the initiated code, as long as the label DEC is handled correctly. It would be best to fix it, though, if you meant DAT.
     
  3. Mo123

    Mo123 Private E-2

    Thanks for this Information.

    I will let you know If I have anymore questions
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds