CSC231 Exercises with conditional jumps
--D. Thiebaut (talk) 08:08, 9 November 2015 (EST)
Exercises on Conditional Jumps
Contents
Finding the Smallest of 3 Ints
- Find the minimum of 3 int variables a, b, and c.
Scanning an array
- Find the largest element of a 1-dimensional array of integers.
Characters and lower/upper case conversion
- Write the code necessary to transform a character from lower- to upper-case, if the character is a letter. The character should not be changed if it is not a letter.
Characters and lower/upper case conversion. Version 2
- Use a boolean function that returns true or false depending on whether the character it receives is lowercase or not.
- What compilers often do: Use the Carry bit to return True or False. STC is an instruction that sets the carry bit to 1. CLC is an instruction that clears the carry bit. JC is an instruction that Jumps if the carry bit is set. JNC is an instruction that jumps if the carry bit is not set.
Execution Time
- Assume we write a loop in java that will scan the text of the book Ulysses, by James Joyce, and transform it from upper- to lower-case. The book contains 1.5 million characters. How long would it take a 1 GHz Pentium to scan the whole string, assumed to be already in memory?
Long/short jumps
- Conditional jumps can jump only +127 bytes down, -128 bytes up in the code. How can we code something like this:
cmp eax,10 jl there ... ... there: ...
- when the instruction at Label there is 1000 bytes away from the jl conditional jump?
Print 2-dimensional arrays
Write the code necessary for printing an array of chars (maze) using for-loops depending on i and j indexes.
;;; ------------------------------------------------------------ ;;; data areas ;;; ------------------------------------------------------------ section .data maze db "################################" maze2 db " # # # " db "######### # # ####### # #" db "# # # # #" db "######### ##############" db "# #### #" db "################################" C equ maze2-maze ; num of columns R equ 7 ; num of rows i dd 0 j dd 0