================================= Say "hello, world!" with assembly ================================= Assembly notation is equivalent to machine code. But more expressive. Here we mainly focus on "seeing" the equivalence. This means every assembly instruction represents exactly one machine instruction. And vice versa, every machine instruction can be represented by one assembly instruction. Expressing machine code with assembly code will be explained in the video. In the assignment you have to do it the way around, i.e. translate machine code instructions into assembly notation. For now, more expressive means that you can write instructions in some symbolic form (e.g. using mnemonics like `addq`), and that we can use decimal, octal or hexadecimal notations for numerals. In upcoming session you will see that assembly code can provide you much more convenience. Video tutorial ============== This video explains the assembly notation described in the __Instruction Set of the ULM__. ---- VIDEO ------------------------------ https://www.youtube.com/embed/SM9ImcAoDcs ----------------------------------------- Here the "hello, world!" program in assembly as shown in the video: ---- CODE (file=session06/hello.s) --------------------------------------------- ldzwq 32, %1 movzbq 0(%1), %2 subq 0, %2, %0 jz 16 putc %2 addq 1, %1, %1 jmp -20 halt 0 .string "hello, world!\n" -------------------------------------------------------------------------------- Using the `-o` you can specify the name of the output file (default would be `a.out`): ---- SHELL (path=session06) ---------------------------------------------------- ulmas -o hello hello.s -------------------------------------------------------------------------------- Here the generated machine code: ---- SHELL (path=session06) ---------------------------------------------------- cat hello -------------------------------------------------------------------------------- And here we run it on the ULM: ---- SHELL (path=session06) ---------------------------------------------------- ulm hello -------------------------------------------------------------------------------- Exercise: What's it doing? ========================== What is the following program doing? Can you express that with some flow chart? ---- CODE(type=s, file=session06/foo.s) ---------------------------------------- jmp 12 addq 1, %1, %1 putc %1 getc %1 subq 0x0A, %1, %0 jnz -16 halt 1 -------------------------------------------------------------------------------- Of course you should test it. Translate it with the ulm assembler ---- SHELL (path=session06) ---------------------------------------------------- ulmas foo.s -------------------------------------------------------------------------------- and then run it on `ulm` or `ulm-qui`. Teaser for learning more about labels ------------------------------------- From this the assembler will generate the same code: ---- CODE(type=s, file=session06/foo.s) ---------------------------------------- jmp check do addq 1, %1, %1 putc %1 getc %1 check subq 0x0A, %1, %0 jnz do halt 1 -------------------------------------------------------------------------------- Exercise: Disassembler ====================== Sorry, we don't have a disassembler for the ULM. So you have to do it! Express the following machine code in assembly: ---- CODE(type=txt) ------------------------------------------------------------ 34 01 02 03 3C 2A 02 03 33 03 02 04 20 01 02 04 28 01 02 04 -------------------------------------------------------------------------------- :links: Instruction Set of the ULM -> http://www.mathematik.uni-ulm.de/numerik/hpc/ss20/hpc0/ulm.pdf :navigate: up -> doc:index back -> doc:session06/page01