================================================ ULM Generator (Part 4): Fetch/Store Instructions [TOC] ================================================ ---- VIDEO ------------------------------ https://www.youtube.com/embed/k3ubwx8tomk ----------------------------------------- Material: Instruction Set and "hello, world!" Program ===================================================== Here the final instruction set that was created: ---- CODE (file=session08/hello/isa.txt, fold) --------------------------------- RRR (OP u 8) (X u 8) (Y u 8) (Z u 8) J26 (OP u 8) (XYZ j 24) U16R (OP u 8) (XY u 16) (Z u 8) 0x01 RRR ulm_halt(ulm_regVal(X)); 0x02 RRR ulm_setReg(ulm_readChar() & 0xFF, X); 0x03 RRR ulm_printChar(ulm_regVal(X) & 0xFF); 0x04 J26 ulm_unconditionalRelJump(XYZ); 0x05 RRR ulm_sub64(X, ulm_regVal(Y), Z); 0x06 J26 ulm_conditionalRelJump(ulm_statusReg[ULM_ZF] == 0, XYZ); 0x07 J26 ulm_conditionalRelJump(ulm_statusReg[ULM_ZF] == 1, XYZ); 0x08 U16R ulm_setReg(XY, Z); 0x09 RRR ulm_fetch64(0, X, 0, 0, ULM_ZERO_EXT, 1, Z); 0x0A RRR ulm_add64(X, ulm_regVal(Y), Z); 0x0B RRR ulm_mul64(ulm_regVal(X), ulm_regVal(Y), Z); -------------------------------------------------------------------------------- And here the "hello, world!\n" program: ---- CODE (file=session08/hello/hello, fold) ----------------------------------- 08 00 20 01 # addr for first char 09 01 00 02 # fetch a char 05 00 02 00 07 00 00 04 # addr for the halt instr 03 02 00 00 0A 01 01 01 04 FF FF FB # addr for fetching a char 01 00 00 00 68 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 0a 00 -------------------------------------------------------------------------------- Quiz ==== Build a computer and write program for it to compute the factorial $n!$ according to the following (not recursive) algorithm described by a flow chart: ---- IMAGE --------------- session08/factorial.png -------------------------- Use the last byte of your program for the variable $n$. Test your program with differnet values (recall that $0! = 1$). Note that the exit code on Unix is truncated to the least significant byte. You can use the debugger to check the actual computed result. Submit your description of the instruction set `isa.txt` and your program `factorial` with `submit hpc quiz07 isa.txt factorial`. ---- VIDEO ------------------------------ https://www.youtube.com/embed/7-kGKX8Hnv0 ----------------------------------------- Browser Test for Flow Charts ============================ For me it is actually easier to generate flow charts with Tikz/Latex. The following chart was created this way and the `dvi` output converted to a `svg` (scaleable vector graphic). However, I was told that some browsers have problems to display that corretly (for me it looks ok on Safarai, Google Chrome and Firefox). So let's discuss in class if this works for us: ---- TIKZ -------------- \begin{tikzpicture} \input{flowchart.tex} \renewcommand\BoxWidth { 6 } \SetMargin{1}{1}{0}{5} \PutStatement{0}{$\text{Address of $n$}\to u(\%1)$} \PutStatement{1}{$u(\text{M}_1(\%1)) \to u(\%2)$} \PutStatement{2}{$u(0\text{x}01) \to u(\%3)$} \PutJump{3}{$u(\%2) = 0$} \PutStatement{4}{$u(\%2) \cdot u(\%3) \bmod 2^{64} \to u(\%3)$} \PutStatement{5}{$(u(\%2) -1) \bmod 2^{64} \to u(\%2)$} \PutJump{6}{} \PutStatement{7}{$\text{halt with exit code $u(\%3)$}$} \AddPath{0}{1} \AddPath{1}{2} \AddPath{2}{3} \AddCondJumpPath{3}{7} \AddPath{3}{4} \AddPath{4}{5} \AddPath{5}{6} \AddJumpPathLeft{6}{3} \end{tikzpicture} ------------------------