diff --git a/.counter.S.swo b/.counter.S.swo new file mode 100644 index 0000000..d0baff0 Binary files /dev/null and b/.counter.S.swo differ diff --git a/.gdb_history b/.gdb_history new file mode 100644 index 0000000..249842e --- /dev/null +++ b/.gdb_history @@ -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 diff --git a/Makefile b/Makefile index bcf2937..d8a1736 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,6 @@ clean:: rm -f $(PROG) *.o *.lst *.bin *.srec TOP=.. -include $(TOP)/Make.rules +include make/Make.rules LDFLAGS+=-Wl,--no-relax diff --git a/counter b/counter new file mode 100755 index 0000000..782d6a0 Binary files /dev/null and b/counter differ diff --git a/counter.S b/counter.S index 1dc1e72..12342b5 100644 --- a/counter.S +++ b/counter.S @@ -1,41 +1,27 @@ - .data -// 0x8000102c -// x7 = PC+(imm <<() -// x7 = - -// = -// 0x8000 0000 + -// 0x8001 0000 -// = 0x8001 0000 - -// aupic x7, 1 - -sentence: .ascii "Become a Prograammermmmmmrr\0" -// ^ -// ^ + .data +sentence: .ascii "My fbbirbst btbry\0" // \0 to bajt zerowy czyli koniec zdania w asm, C = .text .align 2 .globl _start _start: - - la t2, sentence # Load the address of sentence into t2 - 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 +la t2, sentence +li t0, 0x62 //ascii "b" - bne t3, t0, 1f - addi t1, t1, 1 - 1: +li t1, 0x00 // licznik b w sentence - addi t2, t2, 1 # Increment pointer to the next character - j print_loop # Repeat the loop +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: - ebreak # End program (or use an exit system call) +bne t3, t0, 1f // jezeli adres liczby nie jest "b" to prechodzi do 1f pomijanie przyrostu licznika. + 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 diff --git a/counter.bin b/counter.bin new file mode 100755 index 0000000..e9f2064 Binary files /dev/null and b/counter.bin differ diff --git a/counter.lst b/counter.lst new file mode 100644 index 0000000..ec13842 --- /dev/null +++ b/counter.lst @@ -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 : +80000010: 0003ce03 lbu x28,0(x7) +80000014: 000e0a63 beq x28,x0,80000028 +80000018: 005e1463 bne x28,x5,80000020 +8000001c: 00130313 addi x6,x6,1 +80000020: 00138393 addi x7,x7,1 +80000024: fedff06f jal x0,80000010 + +80000028 : +80000028: 00100073 ebreak