Skip to content

Lab 09 fix#160

Open
alexf05 wants to merge 4 commits intomainfrom
lab-09-fix
Open

Lab 09 fix#160
alexf05 wants to merge 4 commits intomainfrom
lab-09-fix

Conversation

@alexf05
Copy link
Copy Markdown

@alexf05 alexf05 commented Mar 26, 2026

Prerequisite Checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Updated relevant documentation (if needed).

Description of changes

This PR resolves the remaining bugs, ABI violations, and typos from the x86_64 transition in lab-09.

Specific fixes include:

  • Reading Materials: Corrected 64-bit calling conventions in the markdown files (e.g., clearing rax for variadic functions like printf and updating 32-bit stack argument examples to 64-bit register arguments).
  • max-c-calls: Fixed a logical bug by changing the signed comparison (jge) to unsigned (jae). Fixed pointer initialization in the solution.
  • regs-preserve: Added the required 16-byte stack alignment (sub rsp, 8) to the support code before calling printf to prevent immediate segfaults. Corrected the stack restoration order (pop rbx vs add rsp, 8) in the solution.

Question for Reviewer (@teodutu): I noticed that the max-c-calls-x86 task currently contains 64-bit code instead of 32-bit, and the max-assembly-calls-x86 task is missing add esp, X stack cleanups for the cdecl calling convention. Should I convert these files back to proper 32-bit assembly in a follow-up commit, or are these x86 legacy folders planned for deletion?

Fix #141

Copy link
Copy Markdown

@teodutu teodutu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right about max-c-calls-x86. Please convert it to x86. As for cleaning the stack in max-assembly-calls-x86, that's not needed because leave already does that by settign rsp = rbp, so leave this as it is.

Comment thread labs/lab-09/tasks/max-c-calls/support/max.asm Outdated
Comment thread labs/lab-09/reading/calling-convention.md
Comment thread labs/lab-09/tasks/max-c-calls/support/max.asm Outdated
Comment thread labs/lab-09/tasks/regs-preserve/support/main.asm Outdated
Comment thread labs/lab-09/tasks/stack-frame/support/print_hello.asm Outdated
Comment thread labs/lab-09/tasks/max-c-calls/support/max.asm Outdated
Comment thread labs/lab-09/tasks/regs-preserve/support/main.asm Outdated
@teodutu
Copy link
Copy Markdown

teodutu commented Mar 30, 2026

alexf05 added 4 commits April 17, 2026 05:38
Update memory-layout and calling-convention reading materials to
correctly reflect the 64-bit System V AMD64 ABI. Add the missing
`xor rax, rax` before variadic function calls and convert 32-bit
stack argument examples to 64-bit register arguments.

Fix #141

Signed-off-by: alexf05 <alexfechet16@gmail.com>
Correct multiple issues introduced during the x86_64 transition:
- max-c-calls: Fix signedness comparison by using `jae` and fix
  pointer initialization bug in the solution. Revert support file.
- regs-preserve: Add required 16-byte stack alignment before calling
  printf and fix the order of stack restoration in the solution.

Fix #141

Signed-off-by: alexf05 <alexfechet16@gmail.com>
Resolved seg fault in reg-preserve
Another minor changes

Signed-off-by: alexf05 <alexfechet16@gmail.com>
for the reading materials

Signed-off-by: alexf05 <alexfechet16@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

labs/lab-09: Check x86_64 version

2 participants