From 25b3381294f6b762041ed54cc054659281cff8b9 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Fri, 23 Jan 2026 10:33:49 +0100 Subject: [PATCH] [SPCA] Fix various errors --- .../code-examples/00_c/00_basics/01_func.c | 6 +++--- .../00_c/00_basics/05_pointers.c | 1 + .../00_c/02_memory/01_mem-corruption.c | 2 +- .../spca/code-examples/01_asm/10_coroutine.c | 4 ++-- .../03_operations/02_condition-codes.tex | 5 +++-- .../parts/00_asm/03_operations/03_jumping.tex | 10 +++++----- .../spca/parts/00_asm/04_control-flow.tex | 2 +- semester3/spca/parts/00_asm/05_stack.tex | 1 + semester3/spca/parts/00_asm/07_coroutines.tex | 1 + .../parts/01_c/01_basics/02_declarations.tex | 6 +++--- .../parts/01_c/01_basics/03_operators.tex | 8 +++++++- .../spca/parts/01_c/01_basics/07_pointers.tex | 6 ++++-- .../01_c/06_floating-point/03_properties.tex | 2 +- .../spca/parts/02_toolchain/02_linking.tex | 5 +++-- semester3/spca/spca-summary.pdf | Bin 701874 -> 702697 bytes 15 files changed, 36 insertions(+), 23 deletions(-) diff --git a/semester3/spca/code-examples/00_c/00_basics/01_func.c b/semester3/spca/code-examples/00_c/00_basics/01_func.c index 399cbbf..9cdc116 100644 --- a/semester3/spca/code-examples/00_c/00_basics/01_func.c +++ b/semester3/spca/code-examples/00_c/00_basics/01_func.c @@ -29,11 +29,11 @@ int get_user_input_int( char prompt[] ) { printf( "Hello World\n" ); } - // Inversed while loop (executes at least once) + // Inverted while loop (executes at least once) do { - input_data -= 1; + input_data_copy -= 1; printf( "Bye World\n" ); - if ( input_data_copy == 0 ) + if ( input_data_copy == 10 ) goto this_is_a_label; } while ( input_data_copy > 1 ); diff --git a/semester3/spca/code-examples/00_c/00_basics/05_pointers.c b/semester3/spca/code-examples/00_c/00_basics/05_pointers.c index d643b82..dff7e6f 100644 --- a/semester3/spca/code-examples/00_c/00_basics/05_pointers.c +++ b/semester3/spca/code-examples/00_c/00_basics/05_pointers.c @@ -30,6 +30,7 @@ int main( int argc, char *argv[] ) { assert( arr == &( arr[ 0 ] ) ); // Evaluates to true int new_arr[ 3 ] = arr; // Compile time error (cannot use other array as initializer) int *new_arr_p = &arr[ 0 ]; // This works + void *t; a_function( &get_user_input_int, c_arr ); diff --git a/semester3/spca/code-examples/00_c/02_memory/01_mem-corruption.c b/semester3/spca/code-examples/00_c/02_memory/01_mem-corruption.c index 3349928..25e4c76 100644 --- a/semester3/spca/code-examples/00_c/02_memory/01_mem-corruption.c +++ b/semester3/spca/code-examples/00_c/02_memory/01_mem-corruption.c @@ -2,7 +2,7 @@ int main( int argc, char **argv ) { int a[ 2 ]; - int *b = malloc( 2 * sizeof( int ) ), *c; + int *b = (int *) malloc( 2 * sizeof( int ) ), *c; a[ 2 ] = 5; // assign past the end of an array b[ 0 ] += 2; // assume malloc zeroes out memory c = b + 3; // mess up your pointer arithmetic diff --git a/semester3/spca/code-examples/01_asm/10_coroutine.c b/semester3/spca/code-examples/01_asm/10_coroutine.c index 5c7e383..8d8de82 100644 --- a/semester3/spca/code-examples/01_asm/10_coroutine.c +++ b/semester3/spca/code-examples/01_asm/10_coroutine.c @@ -35,6 +35,6 @@ struct coroutine *co_new( co_start_fn *start, void *ctxt ) { co->start = start; co->arg = ctxt; setjmp( co->env ); - co->env[ 0 ].__jmpbuf[ 6 ] = ( (uint64_t) ( co->stack ) + CORO_STACK_SIZE ); // Machine specific - co->env[ 0 ].__jmpbuf[ 7 ] = ( (uint64_t) ( start_cl ) ); // Machine specific + co->env[ 0 ].__jmpbuf[ 6 ] = ( (uint64_t) ( co->stack ) + CORO_STACK_SIZE ); + co->env[ 0 ].__jmpbuf[ 7 ] = ( (uint64_t) ( start_cl ) ); // Both lines machine specific } diff --git a/semester3/spca/parts/00_asm/03_operations/02_condition-codes.tex b/semester3/spca/parts/00_asm/03_operations/02_condition-codes.tex index 3305119..81d14d3 100644 --- a/semester3/spca/parts/00_asm/03_operations/02_condition-codes.tex +++ b/semester3/spca/parts/00_asm/03_operations/02_condition-codes.tex @@ -11,12 +11,13 @@ The following condition codes were covered in the lecture (operation: \texttt{t \content{Explicit computation} In the below explanations, we always assume \texttt{src2 = b} and \texttt{src1 = a} -To explicitly compute them, we can use the \texttt{cmpX src2, src1} instruction (with X again any of the size postfixes), +To explicitly compute them, we can use the \texttt{cmpX src2, src1} (i.e. for easier understanding, \texttt{cmpX b, a}) instruction (with X again any of the size postfixes), that essentially computes $(a - b)$ without setting a destination register. + When we execute that instruction, \texttt{CF} is set if \texttt{a < b} (unsigned), \texttt{ZF} is set if \texttt{a == b}, \texttt{SF} is set if \texttt{a < b} (signed) and \texttt{OF} is set as above, where \texttt{t = a - b}. -Another instruction that is used is \texttt{testX src2, src1} (X again a size postfix), and acts like computing \texttt{a \& b} and where \texttt{ZF} is set if \texttt{a \& b == 0} +Another instruction that is used is \texttt{testX src2, src1} (X again a size postfix, easier: \texttt{testX b, a}), and acts like computing \texttt{a \& b} and where \texttt{ZF} is set if \texttt{a \& b == 0} and \texttt{SF} is set if \texttt{a \& b < 0}. \content{Zeroing register} We can use a move instruction, but that is less efficient than using \texttt{xorl reg, reg}, where \texttt{reg} is the 32-bit version of the reg we want to zero. diff --git a/semester3/spca/parts/00_asm/03_operations/03_jumping.tex b/semester3/spca/parts/00_asm/03_operations/03_jumping.tex index 03c475d..4b7f7ba 100644 --- a/semester3/spca/parts/00_asm/03_operations/03_jumping.tex +++ b/semester3/spca/parts/00_asm/03_operations/03_jumping.tex @@ -1,8 +1,8 @@ \subsubsection{Jumping} -To jump, use \texttt{jmp