Skip to content

Commit e1caab6

Browse files
tofergreggCS107E BOT
authored andcommitted
updated intro lecture release
commit cbee0462eaad314cd3353b9d2b2e186f4114a1a7 Author: Chris Gregg <[email protected]> Date: Mon Jan 6 09:06:52 2025 -0800 updated intro lecture release
1 parent d92b55c commit e1caab6

File tree

8 files changed

+144
-1
lines changed

8 files changed

+144
-1
lines changed

_data/unreleased.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ permalink,title,released
3535
"/lectures/OOP/","Object-oriented programming",false
3636
"/lectures/Output/","Output",false
3737
"/lectures/Project/","Project",false
38-
"/lectures/RISC-V/","RISC-V architecture",false
3938
"/lectures/Sensors/","Sensor Input",false
4039
"/lectures/Serial/","Communication and the Serial Protocol",false
4140
"/lectures/Wrap/","Wrap or There and Back Again",false

lectures/RISC-V/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
released: true
3+
permalink: /lectures/RISC-V/
4+
title: "RISC-V architecture"
5+
readings: |
6+
+ Here is a link to the [Ripes simulator](https://ripes.me/) demoed in lecture.
7+
+ Our [one-page guide to RISC-V](/guides/riscv-onepage).
8+
+ (Not light reading, but the real deal on the design of RISC-V) Andrew Waterman's PhD Thesis, "Design of the RISC-V Instruction Set Architecuture" <https://people.eecs.berkeley.edu/~krste/papers/EECS-2016-1.pdf>
9+
---

lectures/RISC-V/code/Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
all: list
2+
3+
OBJDUMP_FLAGS = -d
4+
5+
%.riscv.o: %.c
6+
riscv64-unknown-elf-gcc -O2 -march=rv64im -mabi=lp64 -c $< -o $@
7+
8+
%.intel.o: %.c
9+
clang -O2 -fomit-frame-pointer -c $< -o $@
10+
11+
%.arm.o: %.c
12+
arm-none-eabi-gcc -O2 -c $< -o $@
13+
14+
# Extra recipe to disassemble the compiled program
15+
list: code.riscv.o code.intel.o code.arm.o
16+
arm-none-eabi-objdump $(OBJDUMP_FLAGS) -d code.arm.o >arm.list
17+
riscv64-unknown-elf-objdump $(OBJDUMP_FLAGS) -d code.riscv.o >riscv.list
18+
otool -v -t -j code.intel.o >intel.list
19+
20+
clean:
21+
rm -rf *.o *.bin *.elf *.list *~ code
22+
23+
.PHONY: all clean run list
24+
.PRECIOUS: %.elf

lectures/RISC-V/code/arm.list

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
code.arm.o: file format elf32-littlearm
3+
4+
5+
Disassembly of section .text:
6+
7+
00000000 <set>:
8+
0: e7802101 str r2, [r0, r1, lsl #2]
9+
4: e12fff1e bx lr
10+
11+
00000008 <eitheror>:
12+
8: e3110001 tst r1, #1, 0
13+
c: 13a01000 movne r1, #0, 0
14+
10: e5801020 str r1, [r0, #32]
15+
14: e12fff1e bx lr
16+
17+
00000018 <count_bits>:
18+
18: e2503000 subs r3, r0, #0, 0
19+
1c: 0a000005 beq 38 <count_bits+0x20>
20+
20: e3a00000 mov r0, #0, 0
21+
24: e3130001 tst r3, #1, 0
22+
28: 12800001 addne r0, r0, #1, 0
23+
2c: e1b030a3 lsrs r3, r3, #1
24+
30: 1afffffb bne 24 <count_bits+0xc>
25+
34: e12fff1e bx lr
26+
38: e1a00003 mov r0, r3
27+
3c: e12fff1e bx lr

lectures/RISC-V/code/code.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
void set(int arr[], unsigned long index, int val) {
3+
arr[index] = val;
4+
}
5+
6+
void eitheror(int arr[], int val) {
7+
if (val % 2 == 0) {
8+
arr[8] = val;
9+
} else {
10+
arr[8] = 0;
11+
}
12+
}
13+
14+
int count_bits(unsigned int val) {
15+
int count = 0;
16+
while (val != 0) {
17+
if (val & 1) count++;
18+
val >>= 1;
19+
}
20+
return count;
21+
}

lectures/RISC-V/code/intel.list

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
code.intel.o:
2+
(__TEXT,__text) section
3+
_set:
4+
0000000000000000 8914b7 movl %edx, (%rdi,%rsi,4)
5+
0000000000000003 c3 retq
6+
0000000000000004 6666662e0f1f840000000000 nopw %cs:(%rax,%rax)
7+
_eitheror:
8+
0000000000000010 31c0 xorl %eax, %eax
9+
0000000000000012 40f6c601 testb $0x1, %sil
10+
0000000000000016 0f44c6 cmovel %esi, %eax
11+
0000000000000019 894720 movl %eax, 0x20(%rdi)
12+
000000000000001c c3 retq
13+
000000000000001d 0f1f00 nopl (%rax)
14+
_count_bits:
15+
0000000000000020 31c0 xorl %eax, %eax
16+
0000000000000022 85ff testl %edi, %edi
17+
0000000000000024 741a je 0x40
18+
0000000000000026 89f9 movl %edi, %ecx
19+
0000000000000028 0f1f840000000000 nopl (%rax,%rax)
20+
0000000000000030 89fa movl %edi, %edx
21+
0000000000000032 83e201 andl $0x1, %edx
22+
0000000000000035 01d0 addl %edx, %eax
23+
0000000000000037 d1e9 shrl %ecx
24+
0000000000000039 83ff01 cmpl $0x1, %edi
25+
000000000000003c 89cf movl %ecx, %edi
26+
000000000000003e 77f0 ja 0x30
27+
0000000000000040 c3 retq

lectures/RISC-V/code/riscv.list

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
code.riscv.o: file format elf64-littleriscv
3+
4+
5+
Disassembly of section .text:
6+
7+
0000000000000000 <set>:
8+
0: 00259593 sll a1,a1,0x2
9+
4: 00b50533 add a0,a0,a1
10+
8: 00c52023 sw a2,0(a0)
11+
c: 00008067 ret
12+
13+
0000000000000010 <eitheror>:
14+
10: 0015f793 and a5,a1,1
15+
14: fff78793 add a5,a5,-1
16+
18: 00f5f5b3 and a1,a1,a5
17+
1c: 02b52023 sw a1,32(a0)
18+
20: 00008067 ret
19+
20+
0000000000000024 <count_bits>:
21+
24: 00050793 mv a5,a0
22+
28: 00000513 li a0,0
23+
2c: 00078e63 beqz a5,48 <.L10>
24+
25+
0000000000000030 <.L9>:
26+
30: 0017f713 and a4,a5,1
27+
34: 0017d79b srlw a5,a5,0x1
28+
38: 00070463 beqz a4,40 <.L8>
29+
3c: 0015051b addw a0,a0,1
30+
31+
0000000000000040 <.L8>:
32+
40: fe0798e3 bnez a5,30 <.L9>
33+
44: 00008067 ret
34+
35+
0000000000000048 <.L10>:
36+
48: 00008067 ret

lectures/RISC-V/slides.pdf

19.6 MB
Binary file not shown.

0 commit comments

Comments
 (0)