This shows you the differences between two versions of the page.
alf:res:alfycomputer_32 [2017/05/09 10:46] alexandru.radovici |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== ALF Computer 32 ====== | ||
- | |||
- | ===== Architecture ===== | ||
- | The Alfy ASM language is the assembly language for the ALF32 Computer. This virtual CPU has: | ||
- | |||
- | * A Harvard Architecture (Program RAM and Data RAM are separate) | ||
- | * 32 bits instructions | ||
- | * 64 registers that are 32 bits wide (r0 to r63) | ||
- | * 49 KB of RAM | ||
- | * 49 KB of Program RAM | ||
- | |||
- | <note>All RAM accesses must be 4 Byte aligned</note> | ||
- | |||
- | ===== Simulation ===== | ||
- | |||
- | Alfy ASM is simulated using [[http://www.cs.colby.edu/djskrien/CPUSim/|CPUSim]] version 4. To use the simulator: | ||
- | - Download [[http://www.cs.colby.edu/djskrien/CPUSim/CPUSim4.0.9.zip|CPUSim]] version 4 | ||
- | - Download the [[https://raw.githubusercontent.com/alexandruradovici/alf-alfy-asm-language-public/master/alf_computer32.cpu|alf_computer32.cpu]] | ||
- | - Load it into the simulator | ||
- | |||
- | To run a simulation, you may run it in interactive or non-interactive mode. | ||
- | |||
- | {{ :alf:res:cpusim.png?600 |}} | ||
- | |||
- | Read the [[http://www.cs.colby.edu/djskrien/CPUSim/Version4InstallationInstructions.txt|installation instructions]]. | ||
- | |||
- | ==== Interactive Mode ==== | ||
- | To run CPUSim, open a shell and write | ||
- | |||
- | <code bash> | ||
- | java -classpath .:richtextfx-fat-0.6.10.jar cpusim.Main -m alf_computer32.cpu -t file.asm | ||
- | </code> | ||
- | |||
- | This will open the UI, load the AlfyComputer_32.cpu and the file.asm. | ||
- | |||
- | ==== Non-Interactive Mode ==== | ||
- | To run CPUSim, open a shell and write | ||
- | |||
- | <code bash> | ||
- | java -classpath .:richtextfx-fat-0.6.10.jar cpusim.Main -c -m alf_computer32.cpu -t file.asm | ||
- | </code> | ||
- | |||
- | This will load the alf_computer32.cpu and run the file.asm. | ||
- | |||
- | ===== Running a program ===== | ||
- | After loading a machine and a program, to run it: | ||
- | |||
- | * In the menu bar, go to //Execute// and select //Assemble & load//. This will assemble the program and load it into the program memory | ||
- | * In the Menu bar, go to //Execute// and select //Debug//. This will switch the UI into debug mode. There you can select several options: | ||
- | * //Start Over// - restart the program | ||
- | * //Go// - run the program | ||
- | * //Step by Instr// - go forward one instruction in the program | ||
- | * //Back one Instr// - go back one instruction in the program | ||
- | |||
- | {{:alf:res:assemble.png?200|}}{{:alf:res:debug_mode.png?200|}}{{:alf:res:debug.png?200|}} | ||
- | |||
- | ===== The Alfy ASM Lanaguge ===== | ||
- | |||
- | ^ Instruction ^ Equivalent ^ | ||
- | | set r1 //value// (16 bits) | r1 = value | | ||
- | | mov r1 r2 | r1 = r2 | | ||
- | | load r1 r2 | r2 = MEM [r1] | | ||
- | | store r1 r2 | MEM [r1] = r2 | | ||
- | | pload r1 r2 | r2 = PMEM [r1] | | ||
- | | pstore r1 r2 | PMEM [r1] = r2 | | ||
- | | push r1 | sp = sp - 4 \\ MEM [sp] = r1 | | ||
- | | pop r1 | r1 = MEM [sp] \\ sp = sp + 4 | | ||
- | | pushsp | temp = sp \\ sp = sp - 4 \\ MEM [sp] = temp | | ||
- | | popsp | sp = MEM [sp] | | ||
- | | jmp label | goto label | | ||
- | | run label | sp = sp - 4 \\ MEM [sp] = ip \\ goto etiquete | | ||
- | | ret | sp = sp + 4 \\ ip = MEM [sp] | | ||
- | | (pseudo) label_title: | label label_title | | ||
- | | stop | stop the program | | ||
- | | add r1 r2 r3 | r1 = r2 + r3 | | ||
- | | sub r1 r2 r3 | r1 = r2 - r3 | | ||
- | | mul r1 r2 r3 | r1 = r2 * r3 | | ||
- | | div r1 r2 r3 | r1 = r2 / r3 | | ||
- | | mod r1 r2 r3 | r1 = r2 mod r3 | | ||
- | | dec r1 value (unsigned 16 bits) | r1 = r1 - value | | ||
- | | inc r1 value (unsigned 16 bits) | r1 = r1 + value | | ||
- | | test r1 r2 | t = r1 - r2 | | ||
- | | je label | if t = 0 goto label | | ||
- | | jne label | if t != 0 goto label | | ||
- | | jg label | if t > 0 goto label | | ||
- | | jge label | if t >= 0 goto label | | ||
- | | jl label | if t < 0 goto label | | ||
- | | jle label | if t <= 0 goto label | | ||
- | | and r1 r2 r3 | r1 = r2 AND r3 (bitwise, bit by bit) | | ||
- | | or r1 r2 r3 | r1 = r2 OR r3 (bitwise, bit by bit) | | ||
- | | xor r1 r2 r3 | r1 = r2 XOR r3 (bitwise, bit by bit) | | ||
- | | shl r1 r2 (left shift) | r1 = r1 << r2 | | ||
- | | shr r1 r2 (right shift) | r1 = r1 >> r2 | | ||
- | | read r1 | r1 = read character from keyboard | | ||
- | | write r1 | write character r1 to the display | | ||
- | | readnumber r1 | r1 = read number from keyboard | | ||
- | | writenumber r1 | write number r1 to the display | | ||