kiranvshah / little-man-computer

CS A level coursework
https://littlemancomputer.netlify.app
0 stars 0 forks source link

all instructions need to be able to be given labels #12

Open kiranvshah opened 3 days ago

kiranvshah commented 3 days ago

see https://en.wikipedia.org/wiki/Little_man_computer#Labels, especially the examples beneath. like how you can write label DAT 001, you also need to be able to write label INP, for example this is much like what i did in my prototype of assembly validation. i wonder if some of that logic could be reused for the assembly compilation algorithm (which needs updating) at the moment, branches can only lead to variables created with DAT - which are not instructions so this will not work

kiranvshah commented 3 days ago

example from wikipedia:

     INP
     OUT      // Initialize output 
LOOP BRZ QUIT // Label this memory address as LOOP. If the accumulator value is 0, jump to the memory address labeled
              // QUIT
     SUB ONE  // Subtract the value stored at address ONE from the accumulator
     OUT
     BRA LOOP // Jump (unconditionally) to the memory address labeled LOOP
QUIT HLT      // Label this memory address as QUIT
ONE  DAT 1    // Store the value 1 in this memory address, and label it ONE (variable declaration)
kiranvshah commented 3 days ago

realised this when writing tests for compilation algorithm