0% found this document useful (0 votes)
10 views

Lab 13

Uploaded by

Ngô Linh Chi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lab 13

Uploaded by

Ngô Linh Chi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

SCHOOL OF INFORMATION AND COMMUNICATIONS TECHNOLOGY

LABORATORY 13 REPORT
Course: Assembly language and computer architecture lab
Name: Ngo Minh Ngoc
Student’s ID: 20235984
Week 15: Lab 13. Assembly Programming in ESP32-C3 – using Wokwi Simulation
Assignment 1:

- For GPIO2:
+ Source code:
# Cần định nghĩa hàm init để Wokwi thực hiện chương trình hợp ngữ
.global init

# (Tùy chọn) Sử dụng chỉ thị .eqv để định nghĩa các hằng
.eqv GPIO_ENABLE_REG, 0x60004020 # Thanh ghi cấu hình vào/ra các chân
GPIO
.eqv GPIO_OUT_W1TS_REG, 0x60004008 # Thanh ghi thiết lập chân GPIO

.text
init:
li a1, GPIO_ENABLE_REG
li a2, 0x04
sw a2, 0(a1)
li a1, GPIO_OUT_W1TS_REG
li a2, 0x04
sw a2, 0(a1)

+ Result:
GPIO Source code Result
GPIO2 .text
init:
li a1, GPIO_ENABLE_REG
li a2, 0x04
sw a2, 0(a1)
li a1, GPIO_OUT_W1TS_REG
li a2, 0x04
sw a2, 0(a1)

GPIO3 .text
init:
li a1, GPIO_ENABLE_REG
li a2, 0x08
sw a2, 0(a1)
li a1, GPIO_OUT_W1TS_REG
li a2, 0x08
sw a2, 0(a1)

GPIO4 .text
init:
li a1, GPIO_ENABLE_REG
li a2, 0x10
sw a2, 0(a1)
li a1, GPIO_OUT_W1TS_REG
li a2, 0x10
sw a2, 0(a1)

Assignment 2:
- Source code update:
GPIO Source code
GPIO2 init:
li a1, GPIO_ENABLE_REG # Setup GPIO0 as output
li a2, 0x04
sw a2, 0(a1)

main_loop:
li a1, GPIO_OUT_W1TS_REG # GPIO0 -> HIGH
li a2, 0x04
sw a2, 0(a1)
call delay_asm # Delay

li a1, GPIO_OUT_W1TC_REG # Clear GPIO0


li a2, 0x04
sw a2, 0(a1)
call delay_asm # Delay

j main_loop # Loop

GPIO3 init:
li a1, GPIO_ENABLE_REG # Setup GPIO0 as output
li a2, 0x08
sw a2, 0(a1)

main_loop:
li a1, GPIO_OUT_W1TS_REG # GPIO0 -> HIGH
li a2, 0x08
sw a2, 0(a1)
call delay_asm # Delay

li a1, GPIO_OUT_W1TC_REG # Clear GPIO0


li a2, 0x08
sw a2, 0(a1)
call delay_asm # Delay

j main_loop # Loop

GPIO4 init:
li a1, GPIO_ENABLE_REG # Setup GPIO0 as output
li a2, 0x10
sw a2, 0(a1)

main_loop:
li a1, GPIO_OUT_W1TS_REG # GPIO0 -> HIGH
li a2, 0x10
sw a2, 0(a1)
call delay_asm # Delay

li a1, GPIO_OUT_W1TC_REG # Clear GPIO0


li a2, 0x10
sw a2, 0(a1)
call delay_asm # Delay
j main_loop # Loop

Assignment 3:
Number 7-digit hex equivalent Result
0 0xC0

1 0xF9

2 0x24
3 0x30

4 0x19

5 0x12

6 0x02
7 0xF8

8 0x0

9 0x10
Assignment 4:

- Source code update:


GPIO Source code (only parts that were Result
changed)
GPIO2 .eqv IO_MUX_GPIO0_REG,
0x60009008 # function
register GPIO2
# Read status of GPI2
lw a2, 0(a1)
andi a3, a2, 0x04

GPIO3 .eqv IO_MUX_GPIO0_REG,


0x6000900C # function
register GPIO3
# Read status of GPI3
lw a2, 0(a1)
andi a3, a2, 0x08

GPIO4 .eqv IO_MUX_GPIO0_REG,


0x60009014 # function
register GPIO4
# Read status of GPI4
lw a2, 0(a1)
andi a3, a2, 0x10

Assignment 5:
- Source code:

.global init

.eqv GPIO_ENABLE_REG, 0x60004020 # Enable output GPIO


.eqv GPIO_OUT_REG, 0x60004004 # Output register for GPIO
.eqv IO_MUX_GPIO4_REG, 0x60009014 # Setup function for GPIO4
.eqv IO_MUX_GPIO5_REG, 0x60009018 # Setup function for GPIO5
.eqv IO_MUX_GPIO6_REG, 0x6000901C # Setup function for GPIO6
.eqv IO_MUX_GPIO7_REG, 0x60009020 # Setup function for GPIO7
# Hex values for digits 0-9 (7-segment codes)
# 0xC0 = 0, 0xF9 = 1, 0x24 = 2, 0x30 = 3, 0x19 = 4, 0x12 = 5, 0x02 =6,
0xF8 = 7, 0x0 = 8, 0x10 = 9
.eqv DIGIT_0, 0xC0
.eqv DIGIT_1, 0xF9
.eqv DIGIT_2, 0x24
.eqv DIGIT_3, 0x30
.eqv DIGIT_4, 0x19
.eqv DIGIT_5, 0x12
.eqv DIGIT_6, 0x02
.eqv DIGIT_7, 0xF8
.eqv DIGIT_8, 0x0
.eqv DIGIT_9, 0x10
.text
init:
# Set GPIO output pins (GPIO0 to GPIO7) as outputs
li a1, GPIO_ENABLE_REG
li a2, 0xFF # Set GPIO0 to GPIO7 as output
sw a2, 0(a1)

# Configure GPIO4, GPIO5, GPIO6, GPIO7 for GPIO function


li a2, 0x1000
li a1, IO_MUX_GPIO4_REG
sw a2, 0(a1)

li a1, IO_MUX_GPIO5_REG
sw a2, 0(a1)

li a1, IO_MUX_GPIO6_REG
sw a2, 0(a1)

# Main loop to count from 0 to 9


count_loop:
li a1, GPIO_OUT_REG

# Display 0
li a2, DIGIT_0
sw a2, 0(a1)
call delay_asm

# Display 1
li a2, DIGIT_1
sw a2, 0(a1)
call delay_asm
# Display 2
li a2, DIGIT_2
sw a2, 0(a1)
call delay_asm

# Display 3
li a2, DIGIT_3
sw a2, 0(a1)
call delay_asm

# Display 4
li a2, DIGIT_4
sw a2, 0(a1)
call delay_asm

# Display 5
li a2, DIGIT_5
sw a2, 0(a1)
call delay_asm

# Display 6
li a2, DIGIT_6
sw a2, 0(a1)
call delay_asm

# Display 7
li a2, DIGIT_7
sw a2, 0(a1)
call delay_asm

# Display 8
li a2, DIGIT_8
sw a2, 0(a1)
call delay_asm

# Display 9
li a2, DIGIT_9
sw a2, 0(a1)
call delay_asm

# Loop again
j count_loop

# New delay function


delay_asm:
li a3, 0 # Counter
li a4, 5000000 # Wait time (counting times)
loop_delay:
addi a3, a3, 1 # Increment counter
blt a3, a4, loop_delay # Loop until counter reaches a4
ret

You might also like