diff --git a/semester3/spca/code-examples/01_asm/01_sum.s b/semester3/spca/code-examples/01_asm/01_sum.s index 559552b..4ede34c 100644 --- a/semester3/spca/code-examples/01_asm/01_sum.s +++ b/semester3/spca/code-examples/01_asm/01_sum.s @@ -1,13 +1,13 @@ -sum: // Label - endbr64 // Indirect Branch target (No effect on code's logic) - pushq %rbp // Preserve caller stack frame - movq %rsp, %rbp // Set up new stack frame - movl %edi, -20(%rbp) // Arg1 register -> stack - movl %esi, -24(%rbp) // Arg2 register -> stack - movl -20(%rbp), %edx // stack[Arg1] -> gp register - movl -24(%rbp), %eax // stack[Arg2] -> gp register - addl %edx, %eax // Add Arg1 + Arg2 -> gp register - movl %eax, -4(%rbp) // result -> stack - movl -4(%rbp), %eax // stack[result] -> return register - popq %rbp // Restore caller stack frame - ret // jump back to caller \ No newline at end of file +sum: # Label + endbr64 # Indirect Branch target (No effect on code's logic) + pushq %rbp # Preserve caller stack frame + movq %rsp, %rbp # Set up new stack frame + movl %edi, -20(%rbp) # Arg1 register -> stack + movl %esi, -24(%rbp) # Arg2 register -> stack + movl -20(%rbp), %edx # stack[Arg1] -> gp register + movl -24(%rbp), %eax # stack[Arg2] -> gp register + addl %edx, %eax # Add Arg1 + Arg2 -> gp register + movl %eax, -4(%rbp) # result -> stack + movl -4(%rbp), %eax # stack[result] -> return register + popq %rbp # Restore caller stack frame + ret # jump back to caller diff --git a/semester3/spca/code-examples/01_asm/02_max.s b/semester3/spca/code-examples/01_asm/02_max.s index 465597c..b2bd8e7 100644 --- a/semester3/spca/code-examples/01_asm/02_max.s +++ b/semester3/spca/code-examples/01_asm/02_max.s @@ -1,9 +1,9 @@ max: - cmpl %esi, %edi // Set condition flags - jle .IF // Conditional jump if %edi <= %esi - movl %edi, %edx // %edi -> return register + cmpl %esi, %edi # Set condition flags + jle .IF # Conditional jump if %edi <= %esi + movl %edi, %edx # %edi -> return register jmp .ELSE .IF: - movl %esi, %edx // &esi -> return register + movl %esi, %edx # &esi -> return register .ELSE: - ret \ No newline at end of file + ret diff --git a/semester3/spca/code-examples/01_asm/03_absdiff.s b/semester3/spca/code-examples/01_asm/03_absdiff.s index 9b00d35..5e399ec 100644 --- a/semester3/spca/code-examples/01_asm/03_absdiff.s +++ b/semester3/spca/code-examples/01_asm/03_absdiff.s @@ -1,8 +1,8 @@ absdiff: movl %edi, %eax - subl %esi, %eax // arg2 - arg1 -> eax + subl %esi, %eax # arg2 - arg1 -> eax movl %esi, %edx - subl %edi, %edx // arg1 - arg2 -> edx - cmpl %esi, %edi // Set condition flags - cmovle %edx, %eax // edx -> eax, only if eax <= edx - ret \ No newline at end of file + subl %edi, %edx # arg1 - arg2 -> edx + cmpl %esi, %edi # Set condition flags + cmovle %edx, %eax # edx -> eax, only if eax <= edx + ret diff --git a/semester3/spca/parts/00_asm/04_control-flow.tex b/semester3/spca/parts/00_asm/04_control-flow.tex index ad36b40..e3c60ad 100644 --- a/semester3/spca/parts/00_asm/04_control-flow.tex +++ b/semester3/spca/parts/00_asm/04_control-flow.tex @@ -12,4 +12,4 @@ A function using an \verb|if/else| construct to choose the maximum of $2$ number A function computing the absolute difference $|x-y|$ using an \verb|if/else| construct, might use a conditional \verb|move| instead: -\inputcodewithfilename{gas}{code-examples/01_asm/}{03_absdiff.s} \ No newline at end of file +\inputcodewithfilename{gas}{code-examples/01_asm/}{03_absdiff.s}