my first try
This commit is contained in:
parent
cbb315da34
commit
5de7477dd2
BIN
.counter.S.swo
Normal file
BIN
.counter.S.swo
Normal file
Binary file not shown.
48
.gdb_history
Normal file
48
.gdb_history
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
target extended-remote :3333
|
||||||
|
dashboard -layout registers
|
||||||
|
file counter
|
||||||
|
load
|
||||||
|
si
|
||||||
|
exot
|
||||||
|
exit
|
||||||
|
target extended-remote :3333
|
||||||
|
dashboard -layout registers
|
||||||
|
file counter
|
||||||
|
C
|
||||||
|
exit
|
||||||
|
target extended-remote :3333
|
||||||
|
exit
|
||||||
|
target extended-remote :3333
|
||||||
|
dashboard -layout registers
|
||||||
|
file counter
|
||||||
|
load
|
||||||
|
si
|
||||||
|
erxitC
|
||||||
|
exit
|
||||||
|
target extended-remote :3333
|
||||||
|
dashboard -layout registers
|
||||||
|
file counter
|
||||||
|
loadf
|
||||||
|
load
|
||||||
|
si
|
||||||
|
exit
|
||||||
|
target extended-remote :3333
|
||||||
|
exit
|
||||||
|
target extended-remote :3333
|
||||||
|
dashboard -layout registers memory
|
||||||
|
file counter
|
||||||
|
load
|
||||||
|
si
|
||||||
|
exit
|
||||||
|
target extended-remote :3333
|
||||||
|
dashboard -layout registers memory
|
||||||
|
file counter
|
||||||
|
load
|
||||||
|
si
|
||||||
|
load
|
||||||
|
si
|
||||||
|
si
|
||||||
|
load
|
||||||
|
si
|
||||||
|
xit
|
||||||
|
exit
|
2
Makefile
2
Makefile
@ -9,6 +9,6 @@ clean::
|
|||||||
rm -f $(PROG) *.o *.lst *.bin *.srec
|
rm -f $(PROG) *.o *.lst *.bin *.srec
|
||||||
|
|
||||||
TOP=..
|
TOP=..
|
||||||
include $(TOP)/Make.rules
|
include make/Make.rules
|
||||||
|
|
||||||
LDFLAGS+=-Wl,--no-relax
|
LDFLAGS+=-Wl,--no-relax
|
||||||
|
48
counter.S
48
counter.S
@ -1,41 +1,27 @@
|
|||||||
.data
|
.data
|
||||||
// 0x8000102c
|
sentence: .ascii "My fbbirbst btbry\0" // \0 to bajt zerowy czyli koniec zdania w asm, C =
|
||||||
// x7 = PC+(imm <<()
|
|
||||||
// x7 =
|
|
||||||
|
|
||||||
// =
|
|
||||||
// 0x8000 0000 +
|
|
||||||
// 0x8001 0000
|
|
||||||
// = 0x8001 0000
|
|
||||||
|
|
||||||
// aupic x7, 1
|
|
||||||
|
|
||||||
sentence: .ascii "Become a Prograammermmmmmrr\0"
|
|
||||||
// ^
|
|
||||||
// ^
|
|
||||||
|
|
||||||
.text
|
.text
|
||||||
.align 2
|
.align 2
|
||||||
.globl _start
|
.globl _start
|
||||||
|
|
||||||
_start:
|
_start:
|
||||||
|
la t2, sentence
|
||||||
la t2, sentence # Load the address of sentence into t2
|
li t0, 0x62 //ascii "b"
|
||||||
li t0, 0x72 // ascii 'm'
|
|
||||||
|
|
||||||
li t1, 0x00 // licznik wystapien 'm'
|
|
||||||
|
|
||||||
print_loop:
|
|
||||||
lbu t3, 0(t2) # Load the byte (character) from address in t2
|
|
||||||
beq t3, zero, done_print # If character is zero (null terminator), exit loop
|
|
||||||
|
|
||||||
bne t3, t0, 1f
|
li t1, 0x00 // licznik b w sentence
|
||||||
addi t1, t1, 1
|
|
||||||
1:
|
|
||||||
|
|
||||||
addi t2, t2, 1 # Increment pointer to the next character
|
loop:
|
||||||
j print_loop # Repeat the loop
|
lbu t3, 0(t2) // ladujemy do rejestra t3 adres 1 litery sentece
|
||||||
|
beq t3, zero, koniec # jezeli adres w sentence dojdzie do \0 czyli do konca programm sie skonczy
|
||||||
|
|
||||||
done_print:
|
bne t3, t0, 1f // jezeli adres liczby nie jest "b" to prechodzi do 1f pomijanie przyrostu licznika.
|
||||||
ebreak # End program (or use an exit system call)
|
addi t1, t1, 1 // dodajemy 1 do licznika liter b
|
||||||
|
|
||||||
|
1:
|
||||||
|
|
||||||
|
addi t2, t2, 1 // Tutaj wskaźnik zostanie przesunięty do następnego znaku w linii
|
||||||
|
j loop // skok do poczatku petli
|
||||||
|
|
||||||
|
koniec:
|
||||||
|
ebreak
|
||||||
|
BIN
counter.bin
Executable file
BIN
counter.bin
Executable file
Binary file not shown.
22
counter.lst
Normal file
22
counter.lst
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
counter: file format elf32-littleriscv
|
||||||
|
|
||||||
|
|
||||||
|
Disassembly of section .text:
|
||||||
|
|
||||||
|
80000000 <_start>:
|
||||||
|
80000000: 00001397 auipc x7,0x1
|
||||||
|
80000004: 02c38393 addi x7,x7,44 # 8000102c <__DATA_BEGIN__>
|
||||||
|
80000008: 06200293 addi x5,x0,98
|
||||||
|
8000000c: 00000313 addi x6,x0,0
|
||||||
|
|
||||||
|
80000010 <loop>:
|
||||||
|
80000010: 0003ce03 lbu x28,0(x7)
|
||||||
|
80000014: 000e0a63 beq x28,x0,80000028 <koniec>
|
||||||
|
80000018: 005e1463 bne x28,x5,80000020 <loop+0x10>
|
||||||
|
8000001c: 00130313 addi x6,x6,1
|
||||||
|
80000020: 00138393 addi x7,x7,1
|
||||||
|
80000024: fedff06f jal x0,80000010 <loop>
|
||||||
|
|
||||||
|
80000028 <koniec>:
|
||||||
|
80000028: 00100073 ebreak
|
Loading…
Reference in New Issue
Block a user