Skip to content

Commit c2c701c

Browse files
committed
Add .gitignore, makefile, and cheatsheet.
1 parent d1bf39b commit c2c701c

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

asm1x/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
arg[1-8]
2+
main
3+
mul
4+
*.s

asm1x/GNUmakefile

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
ASMS := $(patsubst %.c,%.s,$(wildcard *.c))
2+
ASM_OBJECTS := $(patsubst %.s,%.o,$(ASMS))
3+
ASM_PROGRAMS := $(shell grep -l main $(wildcard *.[cs]) | sed 's,\.[cs],,' | sort -u)
4+
DEFAULT_ASM_CFLAGS = -O1
5+
DEFAULT_ASM_CFLAGS_DEBUG = -g $(DEFAULT_ASM_CFLAGS)
6+
7+
PROGRAMS = $(ASM_PROGRAMS)
8+
9+
all: $(ASMS) $(PROGRAMS)
10+
11+
ALLPROGRAMS = $(PROGRAMS)
12+
PREFER_GCC ?= 1
13+
14+
include ../common/rules.mk
15+
16+
%.o: %.c $(BUILDSTAMP)
17+
$(call run,$(CC) $(CFLAGS) -O1 $(DEPCFLAGS) -o $@ -c,COMPILE,$<)
18+
19+
$(ASM_OBJECTS): %.o: %.s $(BUILDSTAMP)
20+
$(call run,$(CC) -o $@ -c,ASSEMBLE,$<)
21+
22+
%.noopt.o: %.c $(BUILDSTAMP)
23+
$(call run,$(CC) $(CFLAGS) -O0 $(DEPCFLAGS) -o $@ -c,COMPILE -O0,$<)
24+
25+
%.prof.o: %.c $(BUILDSTAMP)
26+
$(call run,$(CC) $(CFLAGS) -pg -O1 $(DEPCFLAGS) -o $@ -c,COMPILE -pg,$<)
27+
28+
29+
%.s: %.c GNUmakefile
30+
@ARGS=$$(grep '^//!' $< | sed 's/.*! *//'); \
31+
CFLAGS="`echo "$(CFLAGS)" | sed 's/ *-g */ /'`"; \
32+
if test -z "$$ARGS"; then ARGS="$(DEFAULT_ASM_CFLAGS)"; fi; \
33+
$(call xrun,$(CC) $$CFLAGS $$ARGS -o $@ -S $<,COMPILE -S $$ARGS $<) && { $(call cleanasm,$@); }
34+
35+
$(ASM_PROGRAMS): %: %.s
36+
@ARGS=$$(grep '^//!' $< | sed 's/.*! *//'); \
37+
CFLAGS="`echo "$(CFLAGS)" | sed 's/ *-g */ /'`"; \
38+
if test -z "$$ARGS"; then ARGS="$(DEFAULT_ASM_CFLAGS)"; fi; \
39+
$(call xrun,$(CC) $$CFLAGS $$ARGS -o $@ $<,ASSEMBLE $@)
40+
41+
42+
clean:
43+
$(call run,rm -f $(ALLPROGRAMS) *.o *.dSYM *.core,CLEAN)
44+
$(call run,rm -rf $(DEPSDIR))
45+
$(call run,for i in $(ASMS); do x=`basename -s .s $$i`; if grep main $$i $$x.c >/dev/null 2>&1; then rm -f $$x; fi; if test -r $$x.c; then rm -f $$i; fi; done)
46+
47+
insert-f%:
48+
../common/renumber.pl -i f$*
49+
delete-f%:
50+
../common/renumber.pl -d f$*
51+
52+
.PHONY: all clean insert-f% delete-f%
53+

asm1x/cheatsheet.txt

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
CS61 x86-64 Assembly Cheat Sheat
2+
3+
A. Registers
4+
A1. There are a total of <HOWMANY> general purpose (GP) registers.
5+
A2. There are <HOWMANY> GP registers with symbolic names.
6+
A3. They are: <LIST ALL THE NAMED REGISTERS>
7+
A4. There are <HOWMANY> GP registers with number names.
8+
A5. They are: <DESCRIBE/LIST ALL THE NUMBERED REGISTERS>
9+
A6. rip is: <DESCRIBE IT>
10+
A7. rsp is: <DESCRIBE IT>
11+
A8. rbp is: <DESCRIBE IT>
12+
13+
B. Parameter passing
14+
B1. The first argument to a function is passed in register <NAME>.
15+
B2. The second argument to a function is passed in register <NAME>.
16+
B3. The third argument to a function is passed in register <NAME>.
17+
B4. The fourth argument to a function is passed in register <NAME>.
18+
B5. The fifth argument to a function is passed in register <NAME>.
19+
B6. The sixth argument to a function is passed in register <NAME>.
20+
B7. The seventh argument to a function is passed <DESCRIBE HOW>.
21+
22+
C. Addressing modes
23+
C1. $N (for N a number) means:
24+
C2. The expression %REG (for REG a register) means:
25+
C3. (%REG) means:
26+
C4. (%REG, %REG) means:
27+
C5. (%REG, %REG, N) for N=1, 2, 4 or 8 means:
28+
C6. N(<MODE>) for addressing mode C3, C4, or C5 means:
29+
C7. lea<TYPE> (for TYPE one of b,w,l,q) means:
30+
31+
D. x86 flags
32+
For each of the following flags, write down what it means for the flag
33+
to be set:
34+
D1. SF
35+
D2. CF
36+
D3. ZF
37+
D4. OF
38+
39+
E. Instructions whose only purpose is to set flag values:
40+
Explain how each instruction sets the flag registers.
41+
E1. cmp operand1, operand2
42+
E2. test operand1, operand2
43+
44+
F. Jump Instructions
45+
For each jump instruction below, write the expression describing when
46+
the jump will be taken. You will undoubtedly find it useful to
47+
describe this both in terms of which flags you must check but also,
48+
assuming that the previous operation were a cmp or test instruction,
49+
what relationship the operands of the previous instruction have, e.g.,
50+
op1 > op2, or op1 != 0, or whatever applies.
51+
52+
F1. je
53+
F2. jne
54+
F3. js
55+
F4. jns
56+
F5. jg
57+
F6. jge
58+
F7. jl
59+
F8. jle
60+
F9. ja
61+
F10. jae
62+
F11. jb
63+
F12. jbe

0 commit comments

Comments
 (0)