English version draft

Assisted-by: Claude:claude-4.6-sonnet
This commit is contained in:
Andrei Solodovnikov
2026-04-12 13:53:25 +03:00
parent 63260f434e
commit f3fcd27387
74 changed files with 5133 additions and 5875 deletions

View File

@@ -9,43 +9,43 @@ See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
* ------------------------------------------------------------------------------
*/
_start:
# Инициализируем начальные значения регистров
0: 010000b7 li x1, 0x01000000 # сохраняем базовый адрес переключателей
4: 02000137 li x2, 0x02000000 # сохраняем базовый адрес светодиодов
8: 0000b1b7 li x3, 0x0000aaaa # сохраняем спец-код для режима моргания
# Initialize register values
0: 010000b7 li x1, 0x01000000 # save switches base address
4: 02000137 li x2, 0x02000000 # save LED controller base address
8: 0000b1b7 li x3, 0x0000aaaa # save special code for blink mode
c: aaa18193
10: 00005237 li x4, 0x00005555 # сохраняем спец-код для сброса
10: 00005237 li x4, 0x00005555 # save special code for reset
14: 55520213
18: 00100313 li x6, 0x00000001 # сохраняем единицу
1c: 03400293 la x5, trap_handler # псевдоинструкция la аналогично li загружает число,
20: 00028293 # только в случае la это число является адресом
# указанного места (адреса обработчика перехвата)
# данная псевдоинструкция будет разбита на две
# инструкции: lui и addi
24: 30529073 csrw mtvec, x5 # устанавливаем вектор прерывания
28: 000102b7 li x5 , 0x00010000 # подготавливаем маску прерывания единственного
# (нулевого) входа
2c: 30429073 csrw mie, x5 # загружаем маску в регистр маски
18: 00100313 li x6, 0x00000001 # save one
1c: 03400293 la x5, trap_handler # the la pseudo-instruction loads a number similarly to li,
20: 00028293 # but in the case of la the number is the address
# of the specified location (the trap handler address);
# this pseudo-instruction will be split into two
# instructions: lui and addi
24: 30529073 csrw mtvec, x5 # set the interrupt vector
28: 000102b7 li x5 , 0x00010000 # prepare the interrupt mask for the single
# (zeroth) input
2c: 30429073 csrw mie, x5 # load the mask into the mask register
# Вызов функции main
# Call main function
main:
30: 00000063 beq x0, x0, main # бесконечный цикл, аналогичный while (1);
# ОБРАБОТЧИК ПЕРЕХВАТА
# Без стороннего вмешательства процессор никогда не перейдет к инструкциям ниже,
# однако в случае прерывания в программный счетчик будет загружен адрес первой
# нижележащей инструкции.
# Сохраняем используемые регистры на стек
30: 00000063 beq x0, x0, main # infinite loop, equivalent to while (1);
# TRAP HANDLER
# Without external intervention the processor will never reach the instructions below;
# however, upon an interrupt the program counter will be loaded with the address of
# the first instruction below.
# Save used registers to the stack
trap_handler:
34: 0000a383 lw x7, 0(x1) # загружаем значение на переключателях
38: 00338863 beq x7, x3, blink_mode # если пришел спец-код моргания, переходим в blink_mode
3c: 00438a63 beq x7, x4, reset # если пришел спец-код сброса, переходим в reset
40: 00712023 sw x7, 0(x2) # записываем значением с переключателей в светодиоды
44: 30200073 mret # возвращаем управление программе (pc = mepc)
# что означает возврат в бесконечный цикл
34: 0000a383 lw x7, 0(x1) # load the value from the switches
38: 00338863 beq x7, x3, blink_mode # if blink special code received, jump to blink_mode
3c: 00438a63 beq x7, x4, reset # if reset special code received, jump to reset
40: 00712023 sw x7, 0(x2) # write the switch value to LEDs
44: 30200073 mret # return control to the program (pc = mepc),
# which means returning to the infinite loop
blink_mode:
48: 00612223 sw x6, 4(x2) # записываем 1 в led_mode
48: 00612223 sw x6, 4(x2) # write 1 to led_mode
4c: 30200073 mret
reset:
50: 02612223 sw x6, 0x24(x2) # записываем 1 в led_reset
54: 30200073 mret
50: 02612223 sw x6, 0x24(x2) # write 1 to led_reset
54: 30200073 mret