Skip to content

Commit

Permalink
lab3: fix qemu output of version
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiaoqi-LXQ committed Nov 1, 2023
1 parent cdeb9ec commit ab6069e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions docs/lab3/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@ $ echo "export PATH=\$PATH:/opt/cross-tools.gcc_glibc/bin:/opt/gdb/bin:/opt/qemu

```shell
$ qemu-loongarch64 -version
qemu-loongarch64 version 8.1.1
Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
qemu-loongarch64 version 6.2.50 (v6.0.0-7567-gac069a8ffb)
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
```

??? info "检查龙芯 gdb 版本"

```shell
$ loongarch64-unknown-linux-gnu-gdb -v

GNU gdb (GDB) 12.0.50.20210713-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
Expand Down
7 changes: 3 additions & 4 deletions docs/lab3/stack_allocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

而在寄存器分配策略下,变量活跃期间数据都保留在各自的寄存器中,不需要 2.a 的 load 和 2.c 的 store。所以性能上,栈式分配不如寄存器分配,而在实现难度上,栈式分配要简单许多。


## 实验方案

关于变量分配,我们需要为函数中每个变量分配一段栈空间,这个并没有固定的标准,我们提供并已经为你实现好的方案如下:
Expand All @@ -35,9 +34,9 @@
!!! note "注意"

为变量分配空间,实际上就是移动栈指针,这里注意 `$sp` 和 `$fp` 需要**对齐到 16 字节**,详见[汇编介绍中的栈帧布局章节](../common/asm_intro.md/#栈帧布局)。

!!! note "代码"

查阅框架中的代码实现:`src/codegen/CodeGen.cpp` 中 `CodeGen::allocate()`

## 举个例子
Expand Down Expand Up @@ -78,7 +77,7 @@ label_entry:

2. 指令选择:以 IR 中第 5 行的 `%op1 = load i32, i32* %op0` 为例,首先需要将 `%op0` 的值从栈帧加载到寄存器中,然后使用汇编指令 `ld.w` 读取内存,结果即为 `%op1` 的值,最后将其保存回 `%op1` 所在的栈帧位置。

得到的汇编指令如下(建议你读懂数字的来由):
得到的汇编指令如下(建议你读懂数字的来由):

```asm
.text
Expand Down

0 comments on commit ab6069e

Please sign in to comment.