================================================= Assembly Program for Printing an Unsigned Integer [TOC] ================================================= ---- VIDEO ------------------------------ https://www.youtube.com/embed/MEJQXvjGU3g ----------------------------------------- Assignment: Quiz 10 =================== Write a program `printuint.s` that prints the unsigned value stored in its data segment at label `n`. So a skeleton for this program is given by ---- CODE (file=printuint.s) --------------------------------------------------- .data .align 8 n .quad 0x123456789ABCDEF .text /* Your code that prints the unsigned byte at label n */ -------------------------------------------------------------------------------- On `theon` submit your instruction set `isa.txt` and program with the following command ---- CODE (type=txt) ----------------------------------------------------------- submit hpc quiz10 isa.txt printuint.s -------------------------------------------------------------------------------- C as kind of Pseudo-Code ======================== This C code basically reflects how an assembly implementation can be realized. It intensionally has some expressions that normally might not use in this form. C. However, in this way it provides some opportunity to you for reviewing a view things in C ;-) ---- CODE (file=session11/printuint.c) ----------------------------------------- #include // for: int putchar(int); unsigned long long n = 0x123456789ABCDEF; char buf[20]; int main() { // local variables are used as registers (the compiler will actually use // registers here if you compiler with -O1) unsigned long long val; char digit; char *p; // fetch variable n into val val = n; // p point to begin of buf array p = buf; do { digit = val % 10 + '0'; val /= 10; // store ASCII value of digit at *p then increment pointer *(p++) = digit; } while (val != 0); // print stored characters for (; p != buf; putchar(*--p)) { } // print extra newline (not needed for quiz) putchar('\n'); } -------------------------------------------------------------------------------- Test Run after Compiling with gcc --------------------------------- ---- SHELL (path=session11/) --------------------------------------------------- gcc -Wall -o printuint-gcc printuint.c printuint-gcc -------------------------------------------------------------------------------- Test Run after Compiling with ucc --------------------------------- ---- SHELL (path=session11/) --------------------------------------------------- ucc -o printuint-ucc printuint.c printuint-ucc -------------------------------------------------------------------------------- Provided Material ================= You can use this __ULM Instruction Set for Quiz 11__. Here its `isa.txt` source code: :import: session11/io/0_ulm_variants/io/isa.txt [fold] ---- SHELL (path=session11/io/, hide) ------------------------------------------ make refman mkdir -p /home/www/htdocs/numerik/hpc/ss22/hpc0/session11/quiz10/ cp 1_ulm_build/io/refman.pdf /home/www/htdocs/numerik/hpc/ss22/hpc0/session11/quiz10/ -------------------------------------------------------------------------------- :links: ULM Instruction Set for Quiz 11 -> https://www.mathematik.uni-ulm.de/numerik/hpc/ss22/hpc0/session11/quiz10/refman.pdf Compared to the last session three instructions were added: - The instruction `divq X, %Y, %Z` computes the quotient and remainder of an unsigned integer division. Note that the two results are stored in the register pair `%Z` *and* `%{Z + 1}`: ---- LATEX ------------------------------------------------------------------- \begin{array}{lcl} \left\lfloor \frac{u(\%Y)}{u(X)} \right\rfloor & \to & u(\%Z)\\ u(\%Y) \bmod u(X) & \to & u(\%\{Z + 1\})\\ \end{array} ------------------------------------------------------------------------------ - The instruction `movb %X, (%Y)` can be used to store the least significant byte in `%X` at address `%Y`: ---- LATEX ------------------------------------------------------------------- u(\%X) \bmod 2^8 \to u(M_1(a))\;\text{with}\;a = u(\%Y) ------------------------------------------------------------------------------ - The instruction `movq (%X), %Y` can be used to fetch a quad word from address `%X` into register `%Y`: ---- LATEX ------------------------------------------------------------------- u(M_8(a)) \to u(\%Y)\;\text{with}\;a = u(\%X) ------------------------------------------------------------------------------