From 005ad4e9871310ba125623b2a7112695c0497bc4 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 7 Apr 2024 14:56:53 +0200 Subject: [PATCH] Alignment in linker script --- add.s | 17 +++++++++++++++++ link.ld | 3 +++ main.s | 1 - makefile | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 add.s diff --git a/add.s b/add.s new file mode 100644 index 0000000..226ac96 --- /dev/null +++ b/add.s @@ -0,0 +1,17 @@ +.globl add +.text +.align 2 +.type add, @function +add: + addi sp,sp,-32 + sw ra,28(sp) + sw s0,24(sp) + addi s0,sp,32 + sw a0,-20(s0) + lw a5,-20(s0) + slli a5,a5,1 + mv a0,a5 + lw ra,28(sp) + lw s0,24(sp) + addi sp,sp,32 + jr ra diff --git a/link.ld b/link.ld index 8401657..fdcb3ce 100644 --- a/link.ld +++ b/link.ld @@ -7,12 +7,15 @@ SECTIONS { .text : { main.o(.text.*) *(.text) + . = ALIGN(4); } > DRAM .data : { *(.data) + . = ALIGN(4); } > DRAM AT > SRAM .bss : { *(.bss) + . = ALIGN(4); } > DRAM /DISCARD/ : { *(.riscv.attributes) diff --git a/main.s b/main.s index 0483446..5881cc2 100644 --- a/main.s +++ b/main.s @@ -1,6 +1,5 @@ # Define variables .data -.align 4 num1: .word 5 # First number num2: .word 7 # Second number result: .word 0 # Variable to store the result diff --git a/makefile b/makefile index 9d21460..e1c6069 100644 --- a/makefile +++ b/makefile @@ -84,6 +84,9 @@ data: all size: all $(SIZE) $(TARGET) +format: + clang-format -i *.s + # Clean up clean: rm -f $(TARGET) $(OBJS)