help with little man computer

Discussion in 'Software' started by cduval04, Feb 21, 2013.

  1. cduval04

    cduval04 Private E-2

    trying to write a program for school. the program is supposed to do the following:

    Write a program that takes an input value (for example, a number 5). The output should be sum of all numbers from 1 to the value input by the user (in this example, the output would be 1+2+3+4+5 i.e. 15)

    what I dont get is how if say I enter 20 how to get it to know that I entered 20 and just add all the numbers from 1 to 20 like count. would I use the SUB (subtract) command to aid in this? help-I'm stuck!!

    INP
    STA NUM1
    LDA NUM1
    INP
    STA NUM2
    LDA NUM2
    ADD NUM2
    OUT
    HLT
     
  2. foogoo

    foogoo Major "foogoo" Geek

    What language ? assembly?
    pseudo code or basic..

    input "number?"; N
    For Loop = 1 to N
    Cnt = Cnt + Loop
    Next loop
    Print cnt

    You have to loop and add the loop count to the number of times the loop has executed.
     

    Attached Files:

  3. PC-XT

    PC-XT Master Sergeant

    Your code has 2 inputs, but I guess you are trying to make the addition routine into a loop... I would start over making new code, because you will need to plan around a loop.

    Similar to what you were thinking and what Foogoo illustrated, you can allocate one box to store the number (LOOP) and another to store the total (CNT), then subtract one from LOOP and add the resulting number to CNT. Jump back to the subtraction unless LOOP<1. At the end of that, OUT CNT would give the result.
     
    Last edited: Feb 23, 2013
  4. pwillener

    pwillener MajorGeek

  5. pwillener

    pwillener MajorGeek

    Anyway, you will need to form a loop, similar to what foogoo demonstrated, probably using the BRP instruction.
     
  6. PC-XT

    PC-XT Master Sergeant

    It never existed for practicality, just as a teaching tool. You can actually set one up using yourself as the "little man" to better learn how computers work.

    Also, in case the OP didn't catch my mental exercise, "unless LOOP<1" means the same as "if LOOP>=1" in integer math, so pwillener's suggestion and mine are in agreement. I might have been too confusing with that part, but I don't like just giving answers. ;)
     

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