diff options
| author | mo khan <mo@mokhan.ca> | 2025-01-18 13:24:09 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-01-18 13:24:09 -0700 |
| commit | 2dd16b794176b82ccfdb4e87ead8f65e3e049985 (patch) | |
| tree | c71a22ba8d28f703aeb688b8cfe469db8f586d2f | |
| parent | d3ea858fa73381d597116f363f3673b51ffb7663 (diff) | |
Generate assembly language output for assignment 3
| -rw-r--r-- | assignments/3-solution.md | 5 | ||||
| -rw-r--r-- | assignments/3/Makefile | 4 | ||||
| -rw-r--r-- | assignments/3/main.c | 8 | ||||
| -rw-r--r-- | assignments/3/main.s | 45 |
4 files changed, 62 insertions, 0 deletions
diff --git a/assignments/3-solution.md b/assignments/3-solution.md index 1e7a72a..26eb055 100644 --- a/assignments/3-solution.md +++ b/assignments/3-solution.md @@ -6,6 +6,11 @@ Choose ONE exercise each from Chapters 6, 7, and 8 Chapter 6: +13. Write a complete assembly language program (including all necessary +pseudo-ops) that reads in a series of integers, one at a time, and outputs the +largest and smallest values. The input will consist of a list of integer values + + Chapter 7: Chapter 8: diff --git a/assignments/3/Makefile b/assignments/3/Makefile new file mode 100644 index 0000000..aad6e24 --- /dev/null +++ b/assignments/3/Makefile @@ -0,0 +1,4 @@ +default: main.s + +main.s: main.c + gcc -S -fverbose-asm -O2 main.c diff --git a/assignments/3/main.c b/assignments/3/main.c new file mode 100644 index 0000000..12d80e7 --- /dev/null +++ b/assignments/3/main.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main(int argc, char *argv[]) +{ + for (int i = 0; i < 10; i++) { + printf("%d\n", i); + } +} diff --git a/assignments/3/main.s b/assignments/3/main.s new file mode 100644 index 0000000..ebf2625 --- /dev/null +++ b/assignments/3/main.s @@ -0,0 +1,45 @@ + .file "main.c" +# GNU C17 (GCC) version 14.2.1 20240912 (Red Hat 14.2.1-3) (x86_64-redhat-linux) +# compiled by GNU C version 14.2.1 20240912 (Red Hat 14.2.1-3), GMP version 6.2.1, MPFR version 4.2.1, MPC version 1.3.1, isl version none +# GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 +# options passed: -mtune=generic -march=x86-64 -O2 + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "%d\n" + .section .text.startup,"ax",@progbits + .p2align 4 + .globl main + .type main, @function +main: +.LFB11: + .cfi_startproc + pushq %rbx # + .cfi_def_cfa_offset 16 + .cfi_offset 3, -16 +# main.c:5: for (int i = 0; i < 10; i++) { + xorl %ebx, %ebx # i + .p2align 4 + .p2align 3 +.L2: +# main.c:6: printf("%d\n", i); + movl %ebx, %esi # i, + movl $.LC0, %edi #, + xorl %eax, %eax # +# main.c:5: for (int i = 0; i < 10; i++) { + addl $1, %ebx #, i +# main.c:6: printf("%d\n", i); + call printf # +# main.c:5: for (int i = 0; i < 10; i++) { + cmpl $10, %ebx #, i + jne .L2 #, +# main.c:8: } + xorl %eax, %eax # + popq %rbx # + .cfi_def_cfa_offset 8 + ret + .cfi_endproc +.LFE11: + .size main, .-main + .ident "GCC: (GNU) 14.2.1 20240912 (Red Hat 14.2.1-3)" + .section .note.GNU-stack,"",@progbits |
