teaching machines

CS 330 Lecture 16 – Assembly

February 26, 2012 by . Filed under cs330, lectures, spring 2012.

Agenda

Code

ls.c

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/types.h>

int main(int argc, char **argv) {

  for (int i = 0; i < argc; ++i) {
    printf("argv[%d]: %s\n", i, argv[i]);
  }

  char path[256];
 
  printf("Directory?\n");
  int result = scanf("%s", path);

  if (result == EOF) {
    printf("...... Okay.\n");
    exit(1);
  }

  DIR *dir = opendir(path);
  struct dirent *entry;
  while (entry = readdir(dir)) {
    printf("entry->d_name: %s\n", entry->d_name);
  }
  closedir(dir);

  /* free(dir); */
  /* free(entry); */

  return 0;
}

assembly.mk

%.s: %.c
	gcc -fno-asynchronous-unwind-tables -Wall -std=c99 -S -o $@ $<

clean:
	rm -f *.s

noop.c

void foo() {
  5 + 7;
}

twofuncs.c

void a(int i) {
}
void b() {
  a(5);
}

if.c

int max(int a, int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

loop.c

void print() {
  for (int i = 0; i < 5; ++i) {
  }
}

Haiku

Machine code, Latin.
Both unknown. But machine code…
All roads lead to it.