https://wiki.itcollege.ee/api.php?action=feedcontributions&user=Vvelt&feedformat=atomICO wiki - User contributions [en]2024-03-29T09:04:10ZUser contributionsMediaWiki 1.41.0https://wiki.itcollege.ee/index.php?title=Category:I600_Introduction_to_Computers_and_Informatics&diff=100192Category:I600 Introduction to Computers and Informatics2016-01-08T16:49:23Z<p>Vvelt: /* Grading */</p>
<hr />
<div>In this course we'll give an introduction to variety of topics from hardware to software.<br />
The course will follow roughly the same structure as [https://lagunita.stanford.edu/courses/Engineering/CS101/Summer2014/about Computer Science 101 at Stanford University] with more hands-on approach. This course substitutes Estonian courses I100 Sissejuhatus informaatikasse and [http://www.pld.ttu.ee/~teet/itarvutid.html I201 Arvutid].<br />
<br />
Monday lectures will cover more theoretical stuff;<br />
Thursday workshops are for getting started with new topics;<br />
the homework assignments connect theoretical with practice and<br />
Tuesday sessions are for follow up, asking/answering questions and presenting homework.<br />
Attendance won't be tracked, the sessions are there if you need help.<br />
Bring your laptops for Tuesday and Thursday sessions.<br />
<br />
<br />
Course credits: 6 ECTS<br />
<br />
Lecturer: Lauri Võsandi<br />
<br />
E-mail: lauri [donut] vosandi [plus] i600 [ät] gmail [dotchka] com<br />
<br />
<br />
=Grading=<br />
<br />
Grade mapping:<br />
<br />
* 0-50 points, fail<br />
* 51-60 points, pass 1<br />
* 61-70 points, satisfactory 2<br />
* 71-80 points, average 3<br />
* 81-90 points, good 4<br />
* 91-100 points, very good 5<br />
<br />
Grading is split between theory and practice<br />
<br />
* Exam of 50 points, preparation in lectures and general discussion in workshops.<br />
* Assignments, see instructions and points below.<br />
* Extra points for improving quality of wiki articles, extracurricular work and also helping others, see points below.<br />
<br />
Exam will be halfway between oral and written: You'll be given 30 minutes to prepare for several random questions and 15 minutes to discuss what you've answered.<br />
If you don't have prior experience with the topics, it's highly recommended to take part of the sessions in order to pass the exam. You can use a calculator and this wiki page, don't rely on the access to terminal or other software tools. You can not access Internet or any remote computers.<br />
<br />
Exam sections:<br />
<br />
* Execution of ~10 processor instructions<br />
* Bunch of randomly selected questions from this page<br />
* Bunch of questions (how much RAM, how big disk, what wireless chipset) asked about a computer you'll be given<br />
* Gain SSH access to a machine on the network, basic text file editing skills using nano<br />
<br />
Exam times:<br />
<br />
* 12. jan 10:00 - Oliver Aasmets<br />
* 12. jan 10:30 - <Insert name><br />
* 12. jan 11:00 - <Insert name><br />
* 12. jan 11:30 - <Insert name><br />
* 12. jan 13:00 - Artur V. Kerge<br />
* 12. jan 13:30 - <Insert name><br />
* 12. jan 14:00 - Nazmul Hasan <br />
* 12. jan 14:30 - <Insert name><br />
* 12. jan 15:00 - Meelis Hass<br />
* 12. jan 15:30 - <Insert name><br />
* 13. jan 10:00 - Veiko Velt<br />
* 13. jan 10:30 - Etienne Barrier<br />
* 13. jan 11:00 - Alina Kallas<br />
* 13. jan 11:30 - Artur Ovtsinnikov<br />
* 13. jan 13:00 - Sheela Gowry<br />
* 13. jan 13:30 - Dmitri Sim<br />
* 13. jan 14:00 - Ender<br />
* 13. jan 14:30 - Sander Mets<br />
* 13. jan 15:00 - Kristjan Saaremets<br />
* 13. jan 15:30 - Mohanad Aly<br />
<br />
=Lecture: Computer hardware=<br />
<br />
Jargon: CPU, RAM, ROM, HDD, SSD, PCI, PCI Express, USB 2.0, USB 3.0, VGA, HDMI, DVI, LCD, TFT, LED, OLED, AMOLED, CRT, PWM<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/beef71c3-044c-43c9-a326-e1e62cbb5c9b Lecture recording #1]<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/36786bbb-84b6-4604-be6f-c363bf22ce8d Lecture recording #2 starting 12:30]<br />
<br />
[https://docs.google.com/presentation/d/1OzaqTBAUfMOzhG0HZeSJVSszCmFyn4ug35teYJWkyfM/edit?usp=sharing Lecture slides] Random access memory, permanent storage, buses, input devices, display technologies, networking<br />
<br />
Potential exam questions:<br />
<br />
* Different buses and their uses<br />
* What are the differences between hard disk drive (HDD) and solid state drive (SSD)? [http://www.storagereview.com/ssd_vs_hdd]<br />
* What is the purpose of Flash Translation Layer in terms of solid state drives?<br />
* What are difference between volatile/non-volatile, RAM, ROM, EEPROM and where are they used?<br />
* What is data retention?<br />
* What are difference between asynchronous/synchronous, dynamic/static RAM and where are they used?<br />
* What is [https://compsci2014.wikispaces.com/2.1.3+Explain+the+use+of+cache+memory cache]? What is cache coherence?<br />
* What are differences between resistive and capacitive touchscreen? [http://www.alphr.com/realworld/357325/capacitive-or-resistive-whats-the-best-type-of-touchscreen]<br />
* Explain how [http://www.bidouille.org/hack/mousecam computer mouse] works? [http://www.topdesignmag.com/mouse-history-in-photos/ History of computer mouse].<br />
* Explain how [http://www.daskeyboard.com/blog/typing-through-time-the-history-of-the-keyboard/ computer keyboard] works? [http://computer.howstuffworks.com/keyboard.htm HowStuffworks article] [http://www.explainthatstuff.com/computerkeyboards.html Explain that Stuff article] [http://www.daskeyboard.com/blog/typing-through-time-the-history-of-the-keyboard/ Keyboard History]<br />
* Explain how [https://en.wikipedia.org/wiki/Cathode_ray_tube cathode ray tube] (CRT) based screen technology works and name pros/cons. [https://www.youtube.com/watch?v=2czqYV3T_Kc]<br />
* Explain how [https://en.wikipedia.org/wiki/Liquid-crystal_display liquid crystal displays] (LCD) work and name pros/cons. [https://www.youtube.com/watch?v=nCHgmCxGEzY]<br />
* Name screen technologies making use of thin film transistor (TFT) technology? [https://en.wikipedia.org/wiki/Thin-film_transistor]<br />
* Name uses for light polarization filters? [https://en.wikipedia.org/wiki/Polarizing_filter_%28photography%29] [https://en.wikipedia.org/wiki/Polarized_3D_system] <br />
* What are the benefits of [https://en.wikipedia.org/wiki/Twisted_pair twisted pair cabling] and [https://en.wikipedia.org/wiki/Differential_signaling differential signalling]?<br />
* [https://en.wikipedia.org/wiki/Active_matrix Active matrix] vs [https://en.wikipedia.org/wiki/Passive_matrix_addressing passive matrix] in display technology<br />
<br />
Security section: [http://www.bunniestudios.com/blog/?p=3554 Hacking SD cards]<br />
<br />
Assignments:<br />
* [https://wiki.itcollege.ee/index.php/I600_Introduction_to_Computers_and_Informatics#Assignment:_Investigating_PC_hardware Investigating PC hardware]<br />
* [https://wiki.itcollege.ee/index.php/I600_Introduction_to_Computers_and_Informatics#Assignment:_Investigating_embedded_hardware Investigating embedded hardware]<br />
<br />
=Lecture: Storage abstractions=<br />
<br />
In this lecture we'll talk about permanent storage abstractions: block device, disk, partition, file system, directory/folder, file, journaling, FAT32, NTFS, ext4, HFS+<br />
<br />
[https://docs.google.com/presentation/d/1dJ-HMSR9nW8OuZtSTYf5dlFyPsZKGqxlKoEwIHi9h6k/ Lecture slides] <br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/36786bbb-84b6-4604-be6f-c363bf22ce8d Lecture recording] starts at 47:50.<br />
<br />
* What is a [https://en.wikipedia.org/wiki/Block_%28data_storage%29 block device]?<br />
* What is [https://en.wikipedia.org/wiki/Logical_block_addressing logical block addressing] and what are the benefits compared to older [https://en.wikipedia.org/wiki/Cylinder-head-sector cylinder-head-sector addressing] method in terms of harddisks?<br />
* What is a [https://en.wikipedia.org/wiki/Disk_partitioning disk partition]?<br />
* What is a [https://en.wikipedia.org/wiki/File_system file system]?<br />
* What is [https://en.wikipedia.org/wiki/Journaling_file_system#Write_hazards journaling] in terms of filesystems and what are the benefits? Name some journaled filesystems in use nowadays.<br />
<br />
=Lecture: Bootloaders, kernels=<br />
<br />
In this lecture we'll discuss how a computer boots and how an operating system kernel is loaded.<br />
<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/04eeebd1-c892-485a-9123-03abaa3ce3ca Lecture recording #1], first half we'll discuss about first assignment about investigating PC hardware, slides start at 43:40.<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/26f1d40d-7830-4e5c-b783-e061c1e91cfc Lecture recording #2], first 15 minutes we'll discuss about second assignment about investigating embedded hardware, last slides about kernels are discussed from 16:00 up to 27:30. I forgot to switch video input for lecture recording so you'll have to browse slides from the link below :/<br />
<br />
Lecture slides:<br />
[https://docs.google.com/presentation/d/1ybYQEqCgN1KdVW1sLdwtfRogavgzzMQdUfTcAnxNAf4/ bootloaders],<br />
[https://docs.google.com/presentation/d/1xDL27k3z_0I-IKzdjKkwhOhBrg0aOnM0w0u1zDwaEWY/ kernels].<br />
<br />
Jargon: [https://en.wikipedia.org/wiki/BIOS BIOS] (basic input/output system), [https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface UEFI] (Unified Extensible Firmware Interface), bootloader, kernel, process, context switch, x86 real/protected mode, paged virtual memory, swap/pagefile, [https://en.wikipedia.org/wiki/User_space kernelspace/supervisor mode, userspace], [https://en.wikipedia.org/wiki/Protection_ring#Hypervisor_mode hypervisor mode] (ring -1), [https://en.wikipedia.org/wiki/System_Management_Mode#Problems system management mode] aka (ring -2).<br />
<br />
Potential exam questions:<br />
<br />
* What is the role of BIOS/UEFI in x86-based machines?<br />
* Explain step by step how operating system is booted up, see slides for flowchart.<br />
* Describe the functionality provided by general purpose operating system. See architecture of [https://en.wikipedia.org/wiki/Architecture_of_Windows_NT Windows NT], [http://www.elinux.org/Android_Architecture Android], [https://en.wikipedia.org/wiki/Architecture_of_OS_X OS X].<br />
* What are the main differences between [https://en.wikipedia.org/wiki/Real_mode real mode] and [https://en.wikipedia.org/wiki/Protected_mode protected mode] of x86-based processor?<br />
* What happens during context switch?<br />
* What is the purpose of [https://en.wikipedia.org/wiki/Virtual_memory paged virtual memory]?<br />
<br />
<br />
Security section: [https://en.wikipedia.org/wiki/DMA_attack DMA attack], [http://www.outsidaz.org/blog/2007/10/22/resetting-root-password-via-grubkernel-boot-options/ editing GRUB entries to gain root shell] without password prompt, [http://www.theinquirer.net/inquirer/news/2421402/serious-intel-cpu-security-exploit-spotted-in-old-x86-chips 20 years old security exploit in x86 processors].<br />
<br />
=Lecture: Libraries, frameworks=<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/26f1d40d-7830-4e5c-b783-e061c1e91cfc Lecture recording #1], from 00:27:30 up to 1:04:00.<br />
<br />
[https://docs.google.com/presentation/d/1q9kGg5AI3AyXglxpJdLjLMpgRLdbF9dl62gauNmDEG8/edit Lecture slides]<br />
<br />
Jargon: framework, library, [https://en.wikipedia.org/wiki/Application_binary_interface ABI], [https://en.wikipedia.org/wiki/Application_programming_interface API]<br />
<br />
Security section: [http://www.fiercecio.com/story/hackers-exploiting-httpsys-bug-crash-iis-web-servers/2015-04-17 HTTP.sys bug crashes IIS web servers], [http://heartbleed.com/ OpenSSL bug Heartbleed].<br />
<br />
=Lecture: Programming languages=<br />
<br />
In this lecture we'll talk about programming languages<br />
<br />
Lecture recording: [https://echo360.e-ope.ee/ess/echo/presentation/26f1d40d-7830-4e5c-b783-e061c1e91cfc starting from 1:04:00]<br />
<br />
Lecture slides: [https://docs.google.com/presentation/d/1CCZntY7Z-AG_Mice5N2kclDGYI2xVVvRHgWUIs-SxYo/edit programming languages, stack machine]<br />
<br />
Jargon: stack machine, lexer/lexeme, token, abstract syntax tree<br />
<br />
Potential exam questions:<br />
<br />
* What are the major steps of compilation?<br />
* What are the differences between [https://en.wikipedia.org/wiki/Interpreted_language interpreted], [https://en.wikipedia.org/wiki/Just-in-time_compilation JIT-compilation] and [https://en.wikipedia.org/wiki/Compiler traditional compiling]?<br />
* What is [https://en.wikipedia.org/wiki/Control_flow control flow]? Loops? Conditional statements?<br />
<br />
Assignments:<br />
<br />
* [https://wiki.itcollege.ee/index.php/Category:I600_Introduction_to_Computers_and_Informatics#Assignment:_Disassembling_Python Disassembling Python]<br />
* [https://wiki.itcollege.ee/index.php/Category:I600_Introduction_to_Computers_and_Informatics#Assignment:_Investigating_compilers Investigating compilers]<br />
<br />
=Lecture: Data encoding=<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/ca8310e9-e82e-4e47-b90a-2e1801bcfada Lecture recording]<br />
<br />
[https://docs.google.com/presentation/d/1QV_IMOadIEUTBW7Laqw59j8J7Y8HKwvSDmP-swEEx0s Lecture slides]<br />
<br />
In this lecture we'll talk about bits, bytes, integers, strings, pixels, audio encodings, video encoding etc.<br />
<br />
Potential exam questions:<br />
<br />
* What is bit? Nibble? Byte? Word?<br />
* Write 9375 in binary, hexadecimal?<br />
* Write 0xDEADBEEF in decimal?<br />
* What is [https://en.wikipedia.org/wiki/Quantization_%28signal_processing%29 quantization] in terms of signal processing?<br />
* How are [https://en.wikipedia.org/wiki/Integer_%28computer_science%29 integers] stored in binary? What integer range can be described using n bits? How many bits are required to describe integer range from n .. m.<br />
* How are [https://en.wikipedia.org/wiki/Single-precision_floating-point_format single precision] and [https://en.wikipedia.org/wiki/Double-precision_floating-point_format double precision] floating point numbers stored in binary according to [https://en.wikipedia.org/wiki/IEEE_floating_point IEEE754 standard]? [http://lauri.vosandi.com/hdl/arithmetic/floating-point-representation.html Floating-point multiplication]<br />
* What is the difference between CMYK and RGB color models? How are YUV, HSV and HSL colorspaces related to RGB? What are sRGB and YCbCr and where are they used?<br />
* How is data encoded on audio CD-s? What is the [http://lauri.vosandi.com/2013/07/audio-codecs.html capacity of an audio CD]?<br />
* What is sampling rate? What is bit depth? What is resolution?<br />
* What is bitrate?<br />
* What is lossy/lossless compression?<br />
* What is JPEG suitable for? Is JPEG lossy or lossless compression method?<br />
* What is PNG suitable for? Does PNG support compression?<br />
* How are time domain and frequency domain related in terms of signal processing? What is Fourier transform and where it is applied?<br />
<br />
Jargon: 44.1kHz sampling rate, 16-bit audio, RGB565 pixel format, RGB888 pixel format<br />
<br />
Relevant assignments:<br />
<br />
* [https://wiki.itcollege.ee/index.php/Category:I600_Introduction_to_Computers_and_Informatics#Assignment:_Disassembling_Python Disassembling Python]<br />
* [https://wiki.itcollege.ee/index.php/Category:I600_Introduction_to_Computers_and_Informatics#Assignment:_Investigating_compilers Investigating compilers]<br />
<br />
=Lecture: Code execution in processor=<br />
<br />
[https://docs.google.com/presentation/d/18wPDLydyZevMi9F0MX7F6eK-NMBZQzGN4mviF_ft8-E/edit Lecture slides]<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/41440769-1cd5-4166-bd4e-299c2af3d3e0?ec=true Lecture recording #1]<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/7aeb2a04-b0dc-4547-9dee-e541a5f9c99a?ec=true Lecture recording #2] up to 8:35, system calls<br />
<br />
It's highly reccommended to play around with simulators [http://morriswmz.jit.su/static/simple-mips-pipelined.html here is one for MIPS processors].<br />
<br />
In this lecture we'll talk about different processor architectures, instructions, pipelining, function calls, jumps, loops etc.<br />
<br />
Assignments:<br />
<br />
* [https://wiki.itcollege.ee/index.php/Category:I600_Introduction_to_Computers_and_Informatics#Assignment:_Disassembling_Python Disassembling Python]<br />
* [https://wiki.itcollege.ee/index.php/Category:I600_Introduction_to_Computers_and_Informatics#Assignment:_Investigating_compilers Investigating compilers]<br />
<br />
Exam question:<br />
<br />
* Given ~10 instructions and their explainations, follow the instructions and elaborate after every step what happened in the processor?<br />
<br />
=Lecture: Microcontrollers=<br />
<br />
[https://docs.google.com/presentation/d/1qPyzBBfB1TseEzXjcp4-ZjqSnAwbjDmEqyIYcUGFLG0/edit Lecture slides]<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/7aeb2a04-b0dc-4547-9dee-e541a5f9c99a?ec=true Lecture recording] starts at 8:35<br />
<br />
Jargon: microprocessor, microcontroller, coprocessor, floating-point unit (FPU), digital signal processor (DSP), field programmable grid array (FPGA), sensors, actuators, digital input/output, analog input, general purpose input/output (GPIO), interrupt, interrupt handler, timer/counter, pulse-width modulation (PWM), <br />
<br />
Potential exam question:<br />
<br />
* What distinguishes microcontroller from microprocessor?<br />
* What are the differences between Hardvard architecture and von Neumann architecture?<br />
* What is an interrupt?<br />
* What is an timer?<br />
<br />
=Lecture: Introduction to Boole algebra=<br />
<br />
[https://docs.google.com/presentation/d/1Y1rXvt2oXROhW-LZ07B0Sg90D-_u8SlLUZeaxds7f1g/ Lecture slides]<br />
<br />
Exam questions:<br />
<br />
* Simplify A AND A OR B<br />
* Show addition of X and Y in binary<br />
* Show subtraction of X and Y in binary<br />
* Show multiplication of X and Y in binary<br />
<br />
<br />
Assignments:<br />
* [https://wiki.itcollege.ee/index.php/Category:I600_Introduction_to_Computers_and_Informatics#Assignment:_Designing_arithmetic-logic_unit Designing arithmetic-logic unit]<br />
<br />
=Lecture: Hardware description languages=<br />
<br />
[https://docs.google.com/presentation/d/1HO9iPfi8S3ZykuW7IHVm09QamLHiVo6s6lUGwWu4eD4/ Lecture slides]<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/b7ca9eb3-5a9d-4e8c-8c1b-25c2891359ee Lecture recording] starts at 05:00<br />
<br />
Potential exam questions:<br />
<br />
* What are the uses for hardware description languages?<br />
* What is latch?<br />
* What is flip-flop?<br />
* What is mux (multiplexer)?<br />
* What is register? Register file?<br />
* What is ALU?<br />
* What is floating-point unit?<br />
* What is a cache?<br />
* What is a bus?<br />
* Show the circuit diagram for A OR B AND C, NOT A AND B, <insert some other Boole formula here>?<br />
* Show the truth table for <insert Boole formula here>?<br />
* Write the equivalent Boole formula of a circuit diagram.<br />
<br />
<br />
=Lecture: Publishing work=<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/cd2c0e2b-5f48-4a39-89ca-b75801e5d00b Lecture recording]<br />
<br />
[https://docs.google.com/presentation/d/1hCqRjGUx5Yv6iZN4xaz2UICLWbycnM46ctw2zX0g94U/ Lecture slides]<br />
<br />
Potential exam questions:<br />
<br />
* What are the major implications of MIT, BSD and GPL licenses?<br />
* What are the differences between copyright, trademark, trade secret?<br />
* Where would you use waterfall software development model? Where would you use agile?<br />
* What is the purpose of a version control system?<br />
* What would you store in a version control system?<br />
<br />
=Lecture: Algorithms and data structures=<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/1145600e-cef9-40b4-91da-3cc1174e27eb Lecture recording] unfortunately without audio :(<br />
<br />
[https://docs.google.com/presentation/d/1vwJvvRerM0rYBaiE3pEX5GUXRHuVJvjTUDKo8fqTq_A/ Lecture slides]<br />
<br />
Potential exam questions:<br />
<br />
* What is time complexity of algorithm?<br />
* What is space complexity of algorithm?<br />
* What's a good algorithm?<br />
<br />
=Lecture: History=<br />
<br />
Topics: Computer history, Silicon Valley, standards<br />
<br />
[https://echo360.e-ope.ee/ess/echo/presentation/584b21e6-4ead-4cb6-bc41-5c653bc5c3a2 Lecture recording]<br />
<br />
[https://docs.google.com/presentation/d/1Ybld2ABpm9QJSLL-Bodr1a5XI5Hk_KM2q_nZVYu2L0c/edit?usp=sharing Lecture slides]<br />
<br />
Potential example questions:<br />
<br />
* What is [https://en.wikipedia.org/wiki/Moore's_law Moore's law]? What is [https://en.wikipedia.org/wiki/Rock's_law Rock's law]?<br />
* What were the major contributing factors for success of Microsoft, Apple, Google, <your favourite company>?<br />
* What were the major contributing factors to the success of Silicon Valley?<br />
<br />
=Assignment: Investigating PC hardware=<br />
<br />
Goal: Get familiar with your [https://en.wikipedia.org/wiki/X86 laptop hardware]. Get out of the comfort zone of your primary operating system and try out other operating systems. Learn about [https://en.wikipedia.org/wiki/Full_virtualization hardware virtualization].<br />
<br />
Deadline: 16. September<br />
<br />
Credits: 5 points plus extra point for being extra thorough about interpreting what you see.<br />
<br />
Use what you learned in [[Getting started with Ubuntu]] workshop:<br />
<br />
* '''Read the instructions before you act'''.<br />
* Place your preferred ISO image to a memory stick using <code>dd</code> or Win32 Disk Imager and boot it on your personal laptop. You do '''not''' need to install Ubuntu on your harddisk, simply click '''Try Ubuntu''' once the operating system boots off the memory stick and carry out following tasks.<br />
* Open up terminal by pressing <code>Ctrl-Alt-T</code>.<br />
* Use <code>lsb_release -a</code> to check what operating system distribution you're running.<br />
* Use <code>uname -sr</code> to check what operating system kernel you're running. <br />
* Use <code>cat /proc/cpuinfo</code> and check processor information. What CPU model and how many cores your computer has?<br />
* Use <code>arch</code> to check what CPU architecture is being used by the operating system. Is it 32-bit or 64-bit?<br />
* Use <code>cat /proc/meminfo</code> to check memory usage. How much RAM your computer has?<br />
* Use <code>lspci -t -v -nn</code> to enumerate PCI and PCI Express devices, attempt to identify what is what.<br />
* Use <code>lsusb</code> and <code>lsusb -t</code> to enumerate USB devices, again attempt to identify what is what.<br />
* Use <code>fdisk -l</code> to enumerate disks and partitions. How big is your harddisk? How many and how big partitions it has?<br />
* Use <code>lsblk</code> to enumerate block devices.<br />
* Use <code>xrandr</code> to enumerate display outputs. What video output resolutions are available and which one is currently used?<br />
* Use <code>cat /proc/asound/cards</code> to check which audio devices are available.<br />
* Use <code>dmidecode</code> to see even more information about your computer.<br />
* Use <code>ifconfig -a</code> or <code>ip addr list</code> to list all network interfaces.<br />
* Use <code>iwconfig</code> or <code>iw list</code> to list all wireless network interfaces. Is your wireless network interface detected? If not take a guess why?<br />
* Use <code>hcitool dev</code> to list bluetooth host controller. Is your bluetooth device detected?<br />
* Use <code>glxinfo</code> to check what 3D rendering capabilities are available, is it hardware accelerated? (hint: is direct rendering enabled?)<br />
* What [https://en.wikipedia.org/wiki/Sound_card audio card] is your machine using? What bus is it using?<br />
* What [https://en.wikipedia.org/wiki/Graphics_processing_unit graphics controller] is your machine using? What bus is it using?<br />
* What webcam is your machine using? What bus is it using?<br />
* What [https://en.wikipedia.org/wiki/Ethernet wired network] chipset your computer has? What bus is it using? <br />
* What [https://en.wikipedia.org/wiki/IEEE_802.11 wireless network] chipset your computer has? What bus is it using?<br />
* What [https://en.wikipedia.org/wiki/Bluetooth Bluetooth] device your computer has? What bus is it using?<br />
* Is there a [https://en.wikipedia.org/wiki/Mobile_broadband_modem cellular modem] connected and how it's connected?<br />
* Boot the ISO image in VirtualBox and follow the same steps as above, '''what are the differences and why'''?<br />
* Answer to questions above and send it as [https://en.wikipedia.org/wiki/Plain_text plain text] e-mail to Lauri, make sure you '''use the address supplied above with the course code''', otherwise your mail is not searchable in my mailbox. Attach collected command outputs as [https://en.wikipedia.org/wiki/Plain_text plain text] file, do '''not''' send .odt, .doc files, these are not readable on my smartphone. When answering to questions phrase the text in a way that is understandable out of context, so I don't have to open up wiki to understand what you're talking about.<br />
<br />
Note that I can't expect you to install Ubuntu on your physical machine, but I can help if you want to do that. You should have Ubuntu ready to go in a virtual machine at least for subsequent sessions. We're using Ubuntu because it's widely used on servers and in the cloud, so any Ubuntu skills will definitely come handy in future. If you're already familiar with Linux, it's suggested to take a look at other interesting operating systems such as [https://www.freebsd.org/ FreeBSD] or [http://www.openbsd.org/ OpenBSD]. Take a look at [https://www.kali.org/ Kali Linux] if you're interested in penetration testing.<br />
<br />
=Assignment: Investigating embedded hardware=<br />
<br />
Background: Most of the smartphones nowadays are using [https://en.wikipedia.org/wiki/System_on_a_chip SoC] built around [https://en.wikipedia.org/wiki/ARM_architecture ARM] processor. Raspberry Pi is an excellent piece of hardware to for checking out how an ARM-based machine looks like.<br />
<br />
Goal: Get familiar with hardware ARM-based hardware.<br />
<br />
Deadline: 23. September<br />
<br />
Points: 4 points<br />
<br />
Use what you learned in [[Getting started with Ubuntu]] and [[Getting started with Raspberry Pi]] workshops:<br />
<br />
* Read the instructions before you get busy.<br />
* Boot Raspbian on Raspberry Pi.<br />
* Use the commands described in previous assignment to examine the environment of Raspbian on Raspberry Pi. What are the major differences compares to your laptop and virtual machine?<br />
* What buses is Raspberry Pi making use of?<br />
* What filesystems is Raspbian making use of?<br />
* Answer to questions above and send it as e-mail to Lauri, make sure you '''use the address supplied above with the course code''', otherwise your mail is not searchable in my mailbox. Attach collected command outputs as [https://en.wikipedia.org/wiki/Plain_text plain text] file, do '''not''' send .odt, .doc files, these are not readable on a phone. When answering to questions phrase the text in a way that is understandable out of context, so it is not necessary to open up wiki to understand what you're talking about.<br />
<br />
=Assignment: Investigating LAMP=<br />
<br />
[https://en.wikipedia.org/wiki/LAMP_%28software_bundle%29 LAMP] software bundle is consists of Linux-based OS, [https://en.wikipedia.org/wiki/Apache_HTTP_Server Apache web server], [https://en.wikipedia.org/wiki/PHP PHP programming language] runtime and [https://en.wikipedia.org/wiki/MySQL MySQL database].<br />
Most of the web applications on the Internet including Facebook are built on top of LAMP-styled software stack.<br />
Use a Raspberry Pi or Ubuntu virtual machine to set up [https://www.raspberrypi.org/learning/lamp-web-server-with-wordpress/ WordPress], [https://doc.owncloud.org/server/8.1/admin_manual/installation/index.html ownCloud] or any well-known web application that makes use of a database such as MySQL.<br />
To make your life easier also set up SSH public key authentication.<br />
<br />
Goal: Get familiar with LAMP stack. Get comfortable with (SSH) public key authentication.<br />
<br />
Deadline: 30. September<br />
<br />
Points: 4 points<br />
<br />
Tasks:<br />
<br />
* If you're using Ubuntu virtual machine approach, see [[Accessing a virtual machine via SSH connection]]<br />
* Use SSH to connect to your server over the network. If you're using Windows on your laptop use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTY] to gain access to command line and [https://winscp.net/ WinSCP] to copy files, otherwise simply boot Ubuntu in a virtual machine and use <code>ssh username@hostname</code> to invoke commands and <code>sftp://username@hostname</code> in the file browser to access filesystem.<br />
* Set up any of the web applications referenced above. You may be interested in reading also [http://howtoubuntu.org/how-to-install-lamp-on-ubuntu this] and [https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04 this].<br />
* Demonstrate that the web application you installed works in next Tuesday session, screenshots/photos with explanation sent to e-mail above also suffice.<br />
* Optional: Set up SSH public key authentication to <code>enos.itcollege.ee</code>.<br />
* Optional: [https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md Set up public key authentication to your Raspberry Pi]. Windows users might want to take a look at [https://winscp.net/eng/docs/ui_puttygen#obtaining_and_starting_puttygen PuTTYgen instructions].<br />
<br />
Note: You don't have to necessarily use Raspberry Pi - Web application installed in Ubuntu VM is also accepted, also if you're maintaining similar installation of a production server that is accepted as well. [http://www.wampserver.com/en/ WAMP] on Windows is also accepted.<br />
<br />
=Assignment: Set up basic IoT scenario=<br />
<br />
[https://en.wikipedia.org/wiki/Internet_of_Things Internet of Things] is one of the emerging technologies (read: hype). IoT is essentially about getting everything online, including lightbulbs, switches, window shades etc. In this assignment LED symbolizes a light and the task is to implement code which allows user to switch the LED on and off over the network.<br />
<br />
[[File:Raspberry-pi-gpio-18-led bb.png|600px]]<br />
<br />
Goal: Get familiar how Python code can be started up. Build basic [https://en.wikipedia.org/wiki/Internet_of_Things IoT] appliance, a light that can be turned on and off via the Internet.<br />
<br />
Deadline: 7. October<br />
<br />
Points: 4 points<br />
<br />
* Complete the [http://codeacademy.com/tracks/python Python track at CodeAcademy] if you haven't done that yet.<br />
* Follow the wiki page Blinking LED section under [[Getting started with Raspberry Pi]].<br />
* Get an LED blinking on command-line.<br />
* Get LED blinking from Python code.<br />
* Get basic HTTP server running in Python.<br />
* Combine all of the above, build an HTTP server that can be used to turn LED on and off from via web browser.<br />
* Optional: Take a peek at next assignment and upload working version to GitHub.<br />
* Optional: [http://sourceforge.net/p/raspberry-gpio-python/wiki/PWM/ Smoothen the transitions using PWM].<br />
<br />
=Assignment: Collaborating using Git=<br />
<br />
Software development is usually done by several contributors, to facilitate efficient collaboration a distributed version control system is a must. In this assignment you'll upload your code to GitHub and modify fellow student's code to reflect changes in the Raspberry Pi setup:<br />
<br />
[[File:Raspberry-pi-rgb-led bb.png|600px]]<br />
<br />
Deadline: 14. October<br />
<br />
Points: 5<br />
<br />
Goal: Get familiar with distributed version control systems. Collaborate.<br />
<br />
* Create [https://github.com/ GitHub] account if you haven't done so yet.<br />
* Create a Git repository, eg http://github.com/your-username/rpi-iot-example<br />
* Install Git on your Raspberry Pi by using <code>apt-get install git</code>.<br />
* Clone the repository to your Raspberry Pi using <code>git clone http://github.com/your-username/rpi-iot-example</code>.<br />
* Move the Python code created earlier to the Git repository directory.<br />
* Use <code>git add</code> to add the files.<br />
* Configure full name: <code>git config --global user.name "Firstname Surname"</code><br />
* Configure e-mail: <code>git config --global user.email first.last@domain.tld</code> <br />
* Use <code>git commit</code> to create the [http://blog.no-panic.at/2014/10/20/funny-initial-git-commit-messages/ initial commit].<br />
* Use <code>git push</code> to push the commits to GitHub server.<br />
* Set up [https://help.github.com/articles/generating-ssh-keys/ public key authentication between your laptop and GitHub servers], verify that <code>https://github.com/username.keys</code> gives the expected result.<br />
* Use <code>git clone</code> to clone the repository to your laptop. Ubuntu should first <code>apt-get install git</code>, Windows and Mac users might want to take a look at [http://git-scm.com/download/ Git homepage]. If you're looking for graphical user interface take a look at [https://desktop.github.com/ GitHub Desktop] or [https://tortoisegit.org/ TortoiseGit].<br />
* Create [https://en.wikipedia.org/wiki/README README] in the repository directory, populate it with relevant content - what is it about, who made it etc and commit the changes.<br />
* In your Raspberry Pi setup replace the single-color LED with RGB LED as shown above.<br />
* Clone '''fellow student's''' repository and adapt the code to reflect physical changes to the setup, the Python snippet should now permit changing the color of the light, have it blinking and turn it off. Other interesting modes are awarded with extra points.<br />
* Use either [https://www.atlassian.com/git/tutorials/ Atlassian Tutorials], [http://rogerdudler.github.io/git-guide/ git - the simple guide] or [https://try.github.io/ Try Git] as a reference if you get lost.<br />
* Document in the README what GPIO pins are used in the code for red, green and blue. Extra points for making the Python code [https://docs.python.org/2/library/argparse.html#module-argparse configurable from command-line].<br />
* Late submissions will heavily lose points for failure to comply with [http://chris.beams.io/posts/git-commit/ decent commit messages].<br />
* Send Lauri the URL of your repository at GitHub.<br />
<br />
Git resources: [http://git-scm.com/book/en/v2 Pro Git Book] (read the basics to get kickstarted) and [https://www.codecademy.com/en/courses/learn-git/ Codecademy Git course].<br />
<br />
=Assignment: Disassembling Python=<br />
<br />
CPython is the default, most widely used implementation of the Python programming language. CPython is written in C. CPython compiles Python source into bytecode which is interpreted by a Python virtual (stack) machine. This is very similar to what is done with Java. Use [https://docs.python.org/2/library/dis.html dis] to disassemble a Python function into stack machine instructions. Follow [https://docs.python.org/2/library/dis.html#python-bytecode-instructions bytecode instructions] to determine what each instruction does.<br />
<br />
Deadline: 21. October<br />
<br />
<br />
==Example submission==<br />
<br />
Consider following Python function, which calculates the sum of squares. For example sum_of_powers(2, 3) == 14 (1**2 + 2**2 + 3**2):<br />
<br />
def sum_of_powers(exponent, numbers):<br />
counter = 1<br />
return_value = 0<br />
while True:<br />
if counter > numbers:<br />
break<br />
return_value += counter ** exponent<br />
counter += 1<br />
return return_value<br />
<br />
# Following two lines are the ones which produce the instructions shown below<br />
from dis import dis<br />
dis(sum_of_powers)<br />
<br />
Corresponding Python stack machine instructions extracted with <code>dis</code> are following. Columns correspond to: line number in the source code, instruction offset (in bytes), instruction name as listed [https://docs.python.org/2/library/dis.html in dis documentation], <br />
<br />
22 0 LOAD_CONST 1 (1) # Constant of 1 is pushed to stack<br />
3 STORE_FAST 2 (counter) # Pushed value is popped and stored in variable counter<br />
<br />
23 6 LOAD_CONST 2 (0) # Constant of 0 is pushed to stack<br />
9 STORE_FAST 3 (return_value) # Pushed value is popped and stored in variable return_value<br />
<br />
24 12 SETUP_LOOP 43 (to 58) # Loop until instruction no 58 is set up<br />
<br />
25 >> 15 LOAD_FAST 2 (counter) # Value of variable <counter> is pushed to stack<br />
18 LOAD_FAST 1 (numbers) # Value of variable <numbers> is pushed to stack<br />
21 COMPARE_OP 4 (>) # Two topmost values of stack are popped and compared,<br />
# boolean result is pushed back to the top of stack<br />
24 POP_JUMP_IF_FALSE 31 # If top of the stack if False,<br />
# jump to instruction no 31 is performed.<br />
# Top of the stack is popped<br />
<br />
26 27 BREAK_LOOP # Execution jumps out of the loop, the one<br />
# that was set up at inst no 12<br />
28 JUMP_FORWARD 0 (to 31) # Placeholder probably due to the way pipeline is handled<br />
<br />
27 >> 31 LOAD_FAST 3 (return_value) # Value of variable <return_value> is pushed to stack<br />
34 LOAD_FAST 2 (counter) # Value of variable <counter> is pushed to stack<br />
37 LOAD_FAST 0 (exponent) # Value of variable <exponent> is pushed to stack<br />
40 BINARY_POWER # Exponentiation of two topmost values is performed and<br />
# substituted with the result<br />
41 INPLACE_ADD # Two topmost values are added and substituted with the sum<br />
42 STORE_FAST 3 (return_value) # Sum of the addition is stored in variable <return_value><br />
<br />
28 45 LOAD_FAST 2 (counter) # Value of variable <counter> is pushed to stack<br />
48 LOAD_CONST 1 (1) # Constant of 1 is pushed to stack<br />
51 INPLACE_ADD # Two topmost values are added and substituted with the sum<br />
52 STORE_FAST 2 (counter) # Sum is stored in the variable <counter><br />
55 JUMP_ABSOLUTE 15 # Code execution jumps to instruction no 15 (the beginning of the loop)<br />
<br />
29 >> 58 LOAD_FAST 3 (return_value) # The value of variable <return_value> is pushed to stack<br />
61 RETURN_VALUE # Return top of the stack to the function caller<br />
<br />
<br />
In the Python VM the state consists of:<br />
<br />
* Program counter (PC), the number of currently executed instruction<br />
* The stack and most importantly top of stack (TOS)<br />
* Constants extracted from source (co_consts)<br />
* Variables names (co_names)<br />
* Variables values (co_varnames)<br />
* There are *no* registers!<br />
<br />
<br />
Executing the function with arguments exponent=2 and numbers=3 will result in return value of 14, the arguments are already placed in the co_varnames array by the calling function. Also the constants used in the code are present, so you may assume following state in the Python interpreter just before entering the function body:<br />
<br />
-1. stack = []; co_varnames = [2, 3]; co_consts[?, 1, 0]<br />
<br />
The steps that Python VM takes to get to the results are following:<br />
<br />
0. LOAD_CONST 1: stack = [1]<br />
3. STORE_FAST 2: stack = []; co_varnames = [2, 3, 1]<br />
6. LOAD_CONST 2: stack = [0];<br />
9. STORE_FAST 3: stack = []; co_varnames = [2, 3, 1, 0]<br />
12. SETUP_LOOP 43: stack = []; loop is set up, counter is 1<br />
<br />
Here we enter loop body for the first time<br />
<br />
15. LOAD_FAST 2: stack = [1]<br />
18. LOAD_FAST 1: stack = [1, 3]<br />
21. COMPARE_OP 4: stack = [False]<br />
24. POP_JUMP_IF_FALSE 31: stack = []; jump to instruction 31<br />
31. LOAD_FAST 3: stack = [0];<br />
34. LOAD_FAST 2: stack = [0, 1];<br />
37. LOAD_FAST 0: stack = [0, 1, 2];<br />
40. BINARY_POWER: stack = [0, 1]<br />
41. INPLACE_ADD: stack = [1]<br />
42. STORE_FAST 3: stack = []; co_varnames = [2, 3, 1, 1]<br />
45. LOAD_FAST 3: stack = [1];<br />
48. LOAD_CONST 1: stack = [1, 1];<br />
51. INPLACE_ADD: stack = [2]<br />
52. STORE_FAST 2: stack = []; co_varnames = [2, 3, 2, 1]<br />
53. JUMP_ABSOLUTE 15: jump to instruction no 15, counter is 2<br />
<br />
Here we enter loop body for the second time<br />
<br />
15. LOAD_FAST 2: stack = [2]<br />
18. LOAD_FAST 1: stack = [2, 3]<br />
21. COMPARE_OP: stack = [False]<br />
24. POP_JUMP_IF_FALSE 31: stack = []; jump to instruction 31<br />
31. LOAD_FAST 3: stack = [1]; here we have only 1**1<br />
34. LOAD_FAST 2: stack = [1, 2];<br />
37. LOAD_FAST 0: stack = [1, 2, 2];<br />
40. BINARY_POWER: stack = [1, 4]<br />
41. INPLACE_ADD: stack = [5]; here we already have 1**2 + 2**2<br />
42. STORE_FAST 3: stack = []; co_varnames = [2, 3, 2, 5]<br />
45. LOAD_FAST 3: stack = [2];<br />
48. LOAD_CONST 1: stack = [2, 1];<br />
51. INPLACE_ADD: stack = [3]<br />
52. STORE_FAST 2: stack = []; co_varnames = [2, 3, 3, 5]<br />
53. JUMP_ABSOLUTE 15: jump to instruction no 15, counter is 3<br />
<br />
Here we enter the loop body third time<br />
<br />
15. LOAD_FAST 2: stack = [3]<br />
18. LOAD_FAST 1: stack = [3, 3]<br />
21. COMPARE_OP: stack = [False]<br />
24. POP_JUMP_IF_FALSE 31: stack = []; jump to instruction 31<br />
31. LOAD_FAST 3: stack = [5]<br />
34. LOAD_FAST 2: stack = [5, 3];<br />
37. LOAD_FAST 0: stack = [5, 3, 2];<br />
40. BINARY_POWER: stack = [5, 9]<br />
41. INPLACE_ADD: stack = [14]; here we have 1**2 + 2**2 + 3**2<br />
42. STORE_FAST: stack = []; co_varnames = [2, 3, 3, 14]<br />
45. LOAD_FAST 3: stack = [3];<br />
48. LOAD_CONST 1: stack = [3, 1];<br />
51. INPLACE_ADD: stack = [4]<br />
52. STORE_FAST 2: stack = []; co_varnames = [2, 3, 4, 14]<br />
53. JUMP_ABSOLUTE 15: jump to instruction no 15, counter is 4<br />
<br />
Here we enter the loop body fourth (!!!) time<br />
<br />
15. LOAD_FAST 2; stack = [4]<br />
18. LOAD_FAST 1; stack = [4, 3]<br />
21. COMPARE_OP 4; stack = [True]<br />
24. POP_JUMP_IF_FALSE 31; stack = []; but the condition does not hold anymore so we jump out of the loop<br />
27. BREAK_LOOP; break out of the loop<br />
58. LOAD_FAST 3; stack = [14]<br />
61. RETURN_VALUE; return 14 to caller<br />
<br />
==Assignment steps==<br />
<br />
# Select one of the Fibonacci code examples below.<br />
# Use <code>from dis import dis</code> and <code>dis(function_name_goes_here)</code> to disassemble the function to opcodes.<br />
# Comment the stack machine instructions as shown above (3p).<br />
# Invoke the Fibonacci number calculation function with n=2, follow the instructions and elaborate after each instruction executed a) the stack contents b) co_varnames contents c) co_names contents d) what happened as shown above. Note that certain code blocks will be executed repeatedly, which means you'll have more than '''30 instructions executed''' (2p).<br />
<br />
<br />
Fibonacci with iterators:<br />
<br />
<pre><br />
def fib(n):<br />
a,b = 1,1<br />
for i in range(n-1):<br />
a,b = b,a+b<br />
return a<br />
</pre><br />
<br />
Fibonacci with recursion:<br />
<br />
def fib(n):<br />
if n==1 or n==2:<br />
return 1<br />
return fib(n-1) + fib(n-2)<br />
<br />
Fibonacci with infinite loop and breaks:<br />
<br />
def fib3(n):<br />
a,b,i = 1,1,0<br />
while True:<br />
i += 1<br />
if i >= n: break<br />
b,a = a+b,b<br />
return a<br />
<br />
Another variation:<br />
<br />
def fib4(n):<br />
a = 1<br />
b = 1<br />
i = 0<br />
while True:<br />
i += 1<br />
if i >= n: break<br />
s = a + b<br />
a = b<br />
b = s<br />
return a<br />
<br />
=Assignment: Investigating compilers=<br />
<br />
Use what you learned in the [https://wiki.itcollege.ee/index.php/Getting_started_with_GCC Getting started with GCC] session.<br />
See assignment steps below.<br />
Everything you need to understand ARM instructions should be [http://aelmahmoudy.users.sourceforge.net/electronix/arm/chapter2.htm here].<br />
Another good resource seems to be [http://www.davespace.co.uk/arm/introduction-to-arm/ Introduction to ARM] by David Thomas.<br />
See page 14 of [http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf Procedure Call Standard for the ARM® Architecture] if you want to learn more about how function calls are implemented on ARM.<br />
See [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204j/Cihfddaf.html here] for more information about branching instructions: B, BL, BX.<br />
<Insert extemely useful link here yourself><br />
<br />
Deadline: 4. November<br />
<br />
==Example==<br />
<br />
If you don't have Ubuntu installed on your machine skip next step and use SSH to perform these steps remotely at <code>enos.itcollege.ee</code>.<br />
Otherwise install ARM cross-compiler:<br />
<br />
apt-get install gcc-arm-linux-gnueabi<br />
<br />
Consider C snippet for calculating integer [https://en.wikipedia.org/wiki/Exponentiation exponentiation], place it in a file <code>power.c</code>:<br />
<br />
int power(long base, long exponent) {<br />
int counter;<br />
int result = 1;<br />
for (counter = 0; counter < exponent; counter++)<br />
result *= base;<br />
return result;<br />
}<br />
<br />
===Generating assembly===<br />
<br />
Compile ARM assembly of the code snippet:<br />
<br />
arm-linux-gnueabi-gcc -Os -S power.c -o power.s # Cross-compile ARM assembly file power.s from C source code file power.c<br />
cat power.s # Dump the assembly file on terminal<br />
<br />
The compiler should produce something similar to following:<br />
<br />
.arch armv5t<br />
.fpu softvfp<br />
.eabi_attribute 20, 1<br />
.eabi_attribute 21, 1<br />
.eabi_attribute 23, 3<br />
.eabi_attribute 24, 1<br />
.eabi_attribute 25, 1<br />
.eabi_attribute 26, 2<br />
.eabi_attribute 30, 2<br />
.eabi_attribute 34, 0<br />
.eabi_attribute 18, 4<br />
.file "power.c"<br />
.text<br />
.align 2<br />
.global power<br />
.type power, %function<br />
power:<br />
@ args = 0, pretend = 0, frame = 0<br />
@ frame_needed = 0, uses_anonymous_args = 0<br />
@ link register save eliminated.<br />
cmp r1, #0<br />
mov r2, #1<br />
ble .L2<br />
mov r3, #0<br />
.L3:<br />
add r3, r3, #1<br />
cmp r3, r1<br />
mul r2, r0, r2<br />
bne .L3<br />
.L2:<br />
mov r0, r2<br />
bx lr<br />
.size power, .-power<br />
.ident "GCC: (Ubuntu/Linaro 4.7.3-12ubuntu1) 4.7.3"<br />
.section .note.GNU-stack,"",%progbits<br />
<br />
===Commenting the assembly===<br />
<br />
You can safely ignore the lines starting with dot, these are simply hints for the next stage of the compilation process.<br />
Thus you're left only (!!!) 10 actual instructions. Here you can also see what kind of comments are expected from the submission:<br />
<br />
power:<br />
cmp r1, #0 /* Compare register r1 (second argument) contents against constant 0 */ <br />
mov r2, #1 /* Copy the constant 1 to register r2 */<br />
ble .L2 /* Jump to label .L2 if the comparison was false */<br />
mov r3, #0 /* Copy the constant 0 to register r3 */<br />
.L3:<br />
add r3, r3, #1 /* Perform r3 = r3 + 1 */<br />
cmp r3, r1 /* Compare register r3 and r1 (second argument) */<br />
mul r2, r0, r2 /* Perform r2 = r0 (first argument) * r2 */<br />
bne .L3 /* If r3 and r1 were different jump to label .L3<br />
.L2:<br />
mov r0, r2 /* Copy register r2 contents to register r0 */<br />
bx lr /* Jump back to caller */<br />
<br />
<br />
===Analyzing the code===<br />
<br />
Code analysis reveals that registers are mapped as following:<br />
<br />
* <code>r0</code> - argument <code>base</code> and eventually return value<br />
* <code>r1</code> - argument <code>exponent</code><br />
* <code>r2</code> - variable <code>result</code><br />
* <code>r3</code> - variable <code>counter</code><br />
<br />
<br />
We can also see how the <code>for</code> loop gets translated into assembly:<br />
<br />
power:<br />
cmp r1, #0<br />
mov r2, #1<br />
ble .L2<br />
mov r3, #0<br />
.L3:<br />
add r3, r3, #1 <---+<br />
cmp r3, r1 | 4 instructions are executed repeatedly<br />
mul r2, r0, r2 | if exponent is greater than 0<br />
bne .L3 -----------+<br />
.L2:<br />
mov r0, r2<br />
bx lr<br />
<br />
===Stepping through the instructions===<br />
<br />
When we execute the function with for example arguments base=5 and exponent=3 following happens in the processor.<br />
Note that this will essentially calculates 5 ^ 3 (5 to the power of 3) which is 125.<br />
Following has been done manually to illustrate how much time does it take to execute the the function.<br />
<br />
<br />
/* When processor enters the function body the arguments are already placed in registers r0=5 (base), r1=3 (exponent) */<br />
cmp r1, #0 /* Compare exponent to 0 */<br />
mov r2, #1 /* Place constant 1 in register r2,<br />
this corresponds to result = 1 in C code */<br />
ble .L2 /* Exponent was not less than 0, so no jump to L2<br />
mov r3, #0 /* Place constant 0 in register r3,<br />
this corresponds to variable counter */<br />
<br />
add r3, r3, #1 /* Perform r3 = 0 + 1 which results in 1 being stored to r3<br />
this corresponds to first invocation of counter++ in C code */<br />
cmp r3, r1 /* Compare counter (1 in this case) to exponent (3), this will be used by bne instruction below */<br />
mul r2, r0, r2 /* Perform r2 = r0 * r2 which results in 1 * 5 = 5 being placed in r2<br />
this corresponds to first invocation of result *= base in C code */<br />
bne .L3 /* The comparison resulted in counter being not equal to exponent, so we jump back to L3<br />
this corresponds to first invocation of counter < exponent in C code */<br />
<br />
add r3, r3, #1 /* Perform r3 = 1 + 1 which results in 2 being stored to r3<br />
this corresponds to second invocation of counter++ in C code */<br />
cmp r3, r1 /* Compare counter (2 in this case) to exponent (3), this will be used by bne instruction below */<br />
mul r2, r0, r2 /* Perform r2 = r0 * r2 which results 5 * 5 = 25 being placed in r2<br />
this corresponds to second invocation of result *= base in C code */<br />
bne .L3 /* The comparison resulted in counter being not equal to exponent, so we jump back to L3<br />
this corresponds to second invocation of counter < exponent in C code */<br />
<br />
add r3, r3, #1 /* Perform r3 = 2 + 1 which results in 3 being stored to r3<br />
this corresponds to third invocation of counter++ in C code */<br />
cmp r3, r1 /* Compare counter (3 in this case) to exponent (3), this will be used by bne instruction below */<br />
mul r2, r0, r2 /* Perform r2 = r0 * r2 which results 25 * 5 = 125 being placed in r2<br />
this corresponds to third invocation of result *= base in C code */<br />
bne .L3 /* The comparison resulted in counter being equal to exponent, so we DO NOT jump back to L3 */<br />
<br />
mov r0, r2 /* Copy register r2 contents (125) to register r0 */<br />
bx lr /* Jump back to caller */<br />
/* Function returns with 125 placed in r0 this is where caller function should expect the return value */<br />
/* The other registers will still hold whatever values were left there: r1 = 3, r2 = 125, r3 = 3 */<br />
<br />
===ARM registers===<br />
<br />
If you get lost with the ARM register naming conventions use following as a guide.<br />
<br />
ARM7 has 16x 32-bit registers:<br />
<br />
r0 (a1) - Argument/result/scratch register, this is where first function argument is usually placed<br />
r1 (a2) - Argument/result/scratch register, this is where second function argument is placed<br />
r2 (a3) - Argument/scratch register 3<br />
r3 (a4) - Argument/scratch register 4<br />
r4 (v1) - Variable register 1<br />
r5 (v2) - Variable register 2<br />
r6 (v3) - Variable register 3<br />
r7 (v4) - Variable register 4<br />
r8 (v5) - Variable register 5<br />
r9 (v6) - Variable register 6<br />
r10 (v7) - Variable register 7<br />
r11 (fp) - Frame pointer, variable register 8 <br />
r12 (ip) - Intra-procedure call scratch register<br />
r13 (sp) - Stack pointer<br />
r14 (lr) - Link register (to which memory address currently<br />
executing function should return to?)<br />
r15 (pc) - Program counter (what is the memory address of instruction<br />
^ that we are going to execute next?)<br />
|<br />
+- These are simply aliases for the numbered registers and<br />
can be used interchangeably.<br />
<br />
==Assignment steps==<br />
<br />
# Select one of the Fibonacci calculation examples below and use ARM cross compiler as shown above to generate the assembly corresponding to the C source code (1p).<br />
# Remove the compiler hints (lines starting with dot), this should leave you less than 20 instructions. If it's more than that try different optimization flags. Analyze and comment the assembly as shown above (1p).<br />
# Use n=3 as argument and follow the instructions, what values are left in the registers after the function finishes (2p)?<br />
# Optional/extra: Elaborate step by step what happens in the processor: what instruction is being executed and what values are left in registers after instruction finishes? (1p)<br />
# Optional/extra: Recompile with different optimization levels: <code>-Os</code>, <code>-O0</code>, <code>-O1</code>, <code>-O2</code> and <code>-O3</code>. What differences did you notice? (1p)<br />
# Optional/extra: Take a guess which one of the Fibonacci calculation functions below is the slowest? Which one is the fastest? Why? (1p)<br />
# Send your conclusions as e-mail attachment to Lauri, attach the commented assembly, make sure you '''use the address supplied above with the course code''', otherwise your mail is not searchable in my mailbox.<br />
<br />
<br />
Fibonacci calculation using <code>for</code>-loop:<br />
<br />
int fib(n) {<br />
int a = 1;<br />
int b = 1;<br />
int i;<br />
for (i = 0; i < n; i++) {<br />
int s = a + b;<br />
a = b;<br />
b = s;<br />
}<br />
return a;<br />
}<br />
<br />
Fibonacci calculation using recursion:<br />
<br />
int fib2(n) {<br />
if (n == 1 || n== 2) {<br />
return 1;<br />
} else {<br />
return fib(n-1) + fib(n-2);<br />
}<br />
}<br />
<br />
Fibonacci calculation using <code>while</code>-loop:<br />
<br />
int fib4(n) {<br />
int a = 1;<br />
int b = 1;<br />
int i = 0;<br />
while(1) {<br />
i += 1;<br />
if (i >= n) { break; }<br />
int s = a + b;<br />
a = b;<br />
b = s;<br />
}<br />
return a;<br />
}<br />
<br />
=Assignment: Investigating microcontrollers=<br />
<br />
In this assignment we use Arduino to implement traffic lights for [http://www.nobleled.com/uploads/110833/100_101.jpg crossroads].<br />
If you don't care much about doing this assignment hands on, you can give a try [https://123d.circuits.io/ online].<br />
<br />
==Assignment steps==<br />
<br />
* Install Arduino IDE on your personal machine, on Windows/Mac check out [https://www.arduino.cc/ Arduino homepage] for instructions, on Ubuntu <code>apt-get install arduino</code> should suffice. You can also use school computers, Ubuntu has Arduino preinstalled.<br />
* From Arduino IDE menu open up File -> Examples -> 01. Basic -> Blink<br />
* In Arduino IDE menu Tools -> Board -> Arduino Mega2560<br />
* In Arduino IDE menu Tools -> Serial port -> Select what makes sense<br />
* On Ubuntu you may have to add yourself to the dialout group before you can access the serial ports. Use the command <code>sudo gpasswd -a $USER dialout</code>, log out and log in again to your PC.<br />
* Press the second button in the toolbar to upload the code, make sure the changes take effect on the board. You should see on-board LED blinking.<br />
* Connect some LED-s to the board. '''MAKE SURE YOU USE RESISTORS TO PROTECT LED-s AND THE BOARD'''<br />
* Implement traffic light cycle using <code>digitalWrite</code> and <code>delay</code> in the <code>loop</code> function (3p)<br />
* Use interrupts to read button presses, see example below. Pressing the button should toggle the LED now (1p)<br />
* Extra: Use [https://www.arduino.cc/en/Reference/AnalogWrite PWM] to implement smoother blinking (1p)<br />
* Extra: Use [http://lauri.vosandi.com/arduino/lcd1602-key-shield.html LCD1602] shield to display countdown (1p)<br />
* Use [https://www.arduino.cc/en/Reference/Serial serial] interface to send messages to your PC.<br />
* You can find useful code snippets for Robotics club equipment [http://lauri.vosandi.com/arduino here]<br />
<br />
==Code example: reading button press with interrupts==<br />
<br />
Set up a push button as shown below:<br />
<br />
[[File:Arduino-pushbutton_bb.png|500px]]<br />
<br />
Insert following code to Arduino IDE and upload it to Arduino, verify that it works:<br />
<br />
int led = 13;<br />
int button = 2;<br />
int flag = LOW;<br />
<br />
void setup() {<br />
pinMode(led, OUTPUT); // Set up pin 13 as digital output<br />
pinMode(button, INPUT); // Set up pin 9 as digital input<br />
digitalWrite(button, HIGH); // Turn in pull-up resistor<br />
<br />
// Associate interrupt handler with an event<br />
attachInterrupt(digitalPinToInterrupt(button), onButtonPressed, FALLING);<br />
}<br />
<br />
void onButtonPressed() {<br />
// Keep this as short as possible<br />
flag = HIGH;<br />
}<br />
<br />
void loop() {<br />
// Do something useful or let processor sleep here<br />
if (flag) {<br />
digitalWrite(led, HIGH);<br />
delay(2000);<br />
flag = LOW;<br />
}<br />
<br />
digitalWrite(led, LOW);<br />
delay(50);<br />
}<br />
<br />
==Code example: Cycling through different traffic light states==<br />
<br />
Add LED-s to the design:<br />
<br />
[[File:Traffic-lights_bb.png|500px]]<br />
<br />
Use following as hint to implement cycling through traffic light states:<br />
<br />
// Define pin numbers<br />
int car_green = 5;<br />
int car_yellow = 6;<br />
int car_red = 7;<br />
<br />
// For LED-s we're sinking the 5V voltage, hence LED is turned on when voltage on the pin is LOW<br />
int on = LOW;<br />
int off = HIGH;<br />
<br />
void setup() {<br />
pinMode(car_green, OUTPUT);<br />
pinMode(car_yellow, OUTPUT);<br />
pinMode(car_red, OUTPUT);<br />
digitalWrite(cars_yellow, off);<br />
Serial.begin(9600);<br />
}<br />
<br />
void loop() {<br />
Serial.println("Cars green, pedestrians red for 5 seconds");<br />
digitalWrite(cars_red, off);<br />
digitalWrite(cars_green, on);<br />
delay(5000);<br />
<br />
Serial.println("Green for cars is blinking 5 seconds");<br />
for(int j = 0; j < 10; j++) {<br />
digitalWrite(cars_green, j % 2 == 0);<br />
delay(500);<br />
}<br />
<br />
Serial.println("Cars red, pedestrians green for 5 seconds");<br />
digitalWrite(cars_green, off);<br />
digitalWrite(cars_red, on);<br />
delay(5000);<br />
}<br />
<br />
<br />
==Skeleton of the final submission==<br />
<br />
The real traffic light has of course a little bit more states:<br />
<br />
1. Cars green, pedestrians red for 10 seconds<br />
2. Cars green **blinking**, pedestrians red for 2 seconds<br />
3. Cars red, pedestrians green for 10 seconds<br />
4. Cars red, pedestrians green **blinking** for 2 seconds<br />
5. Cars yellow, pedestrians red for 2 seconds<br />
<br />
So your final code will look something like this:<br />
<br />
// Define pin numbers here<br />
<br />
// Initially the flag is low<br />
int pedestrian_requested_crossing = LOW;<br />
<br />
void setup() {<br />
// Initialize necessary pins as digital outputs<br />
// Reset pins with digitalWrite<br />
<br />
// Initialize button pin as digital input<br />
// Enable pull-up resistor on button pin<br />
// Associate button interrupt handler function (onButtonPressed) below with the event on the button<br />
<br />
}<br />
<br />
void onButtonPressed() {<br />
// Here set pedestrian_requested_crossing flag to HIGH<br />
// Don't do anything else here!<br />
}<br />
<br />
void loop() {<br />
Serial.println("Cars green, pedestrians red for 5 seconds");<br />
digitalWrite(cars_red, off);<br />
digitalWrite(cars_green, on);<br />
// Set pedestrian lights here<br />
delay(5000);<br />
<br />
if (pedestrian_requested_crossing) {<br />
<br />
Serial.println("Green for cars is blinking 5 seconds");<br />
for(int j = 0; j < 10; j++) {<br />
digitalWrite(cars_green, j % 2 == 0);<br />
delay(500);<br />
}<br />
<br />
Serial.println("Cars red, pedestrians green for 5 seconds");<br />
digitalWrite(cars_green, off);<br />
digitalWrite(cars_red, on);<br />
// Set pedestrian lights here<br />
delay(5000);<br />
<br />
// Add another state here<br />
<br />
// And another state here<br />
<br />
// Reset flag here<br />
}<br />
}<br />
<br />
=Assignment: Adders with NAND gates=<br />
<br />
In this assignment we use chips to build an adder. Get max points (4p) by wiring up half adder and double your points (8p) if you can make full adder work as well :)<br />
<br />
[[File:53-7400n-detailed.png]]<br />
<br />
<br />
Each SN74HC03N chip contains four NAND gates arranged like this, observe the pit on the left. VCC corresponds to 5V power supply and GND corresponds to ground or 0V.<br />
<br />
<br />
==Half adder==<br />
<br />
Each [http://www.ti.com/lit/gpn/sn74hc03 SN74HC03] contains 4 NAND gates.<br />
Use breadboard to wire up half adder with 7400 chips (4p):<br />
<br />
[[File:Half-adder_bb.png|700px]]<br />
<br />
The truth table for half adder:<br />
<br />
A | B | Cout | Sum | Human readable (how many bits are high?)<br />
-----+-----+------+------+-------------------------------------------<br />
0 | 0 | 0 | 0 | 0<br />
-----+-----+------+------+-------------------------------------------<br />
0 | 1 | 0 | 1 | 1<br />
-----+-----+------+------+-------------------------------------------<br />
1 | 0 | 0 | 1 | 1<br />
-----+-----+------+------+-------------------------------------------<br />
1 | 1 | 1 | 0 | 2<br />
<br />
==Full adder==<br />
<br />
You can double your points if you manage to wire up a full adder (+4p)<br />
<br />
[[File:Nand-full-adder.png]]<br />
<br />
On a breadboard it looks a bit messy, but if you pay attention to gate numbering as shown above it should make your life significantly easier.<br />
The gates 1, 2, 3, 4 are placed in the leftmost chip; 5, 6, 7, 8 are placed in the middle one and gate 9 is the only one in the rightmost chip:<br />
<br />
<br />
<br />
[[File:Full-adder_bb.png|700px]]<br />
<br />
<br />
A | B | Cin | Cout | Sum | Human readable (how many bits are high?)<br />
-----+-----+-----+------+------+-------------------------------------------<br />
0 | 0 | 0 | 0 | 0 | 0<br />
-----+-----+-----+------+------+-------------------------------------------<br />
0 | 0 | 1 | 0 | 1 | 1<br />
-----+-----+-----+------+------+-------------------------------------------<br />
0 | 1 | 0 | 0 | 1 | 1<br />
-----+-----+-----+------+------+-------------------------------------------<br />
0 | 1 | 1 | 1 | 0 | 2<br />
-----+-----+-----+------+------+-------------------------------------------<br />
1 | 0 | 0 | 0 | 1 | 1<br />
-----+-----+-----+------+------+-------------------------------------------<br />
1 | 0 | 1 | 1 | 0 | 2<br />
-----+-----+-----+------+------+-------------------------------------------<br />
1 | 1 | 0 | 1 | 0 | 2<br />
-----+-----+-----+------+------+-------------------------------------------<br />
1 | 1 | 1 | 1 | 1 | 3<br />
<br />
==Unittest==<br />
<br />
Use following code snippet on Arduino to test the circuit, it will shuffle through all the possible inputs and test whether the expected output is on the output pins.<br />
If you see <code>sum</code> or <code>cout</code> outputs giving 0 all the time it's likely you have resistors of too low resistance in the circuit which is draining all the voltage on the NAND gate output pins.<br />
<br />
int PIN_A = 2;<br />
int PIN_B = 3;<br />
int PIN_CIN = 4;<br />
int PIN_SUM = 5;<br />
int PIN_COUT = 6;<br />
<br />
void setup() {<br />
// Set up serial<br />
Serial.begin(9600);<br />
<br />
// Set up operands<br />
pinMode(PIN_A, OUTPUT);<br />
pinMode(PIN_B, OUTPUT);<br />
pinMode(PIN_CIN, OUTPUT);<br />
digitalWrite(PIN_A, HIGH);<br />
digitalWrite(PIN_B, HIGH);<br />
digitalWrite(PIN_CIN, HIGH);<br />
<br />
// Set up measurement pins<br />
pinMode(PIN_SUM, INPUT);<br />
pinMode(PIN_COUT, INPUT);<br />
digitalWrite(PIN_SUM, HIGH); // Enable pull-up resistor<br />
digitalWrite(PIN_COUT, HIGH); // Enable pull-up resistor<br />
}<br />
<br />
void test(int a, int b, int cin) {<br />
int cout = a && b || a && cin || b && cin;<br />
int sum = a ^ b ^ cin;<br />
<br />
digitalWrite(PIN_A, a);<br />
digitalWrite(PIN_B, b);<br />
digitalWrite(PIN_CIN, cin);<br />
<br />
Serial.print("Writing: a=");<br />
Serial.print(a);<br />
Serial.print(", b=");<br />
Serial.print(b);<br />
Serial.print(", cin=");<br />
Serial.print(cin);<br />
Serial.print(" Expecting: sum=");<br />
Serial.print(sum);<br />
Serial.print(", cout=");<br />
Serial.print(cout);<br />
<br />
int measured_sum = digitalRead(PIN_SUM);<br />
int measured_cout = digitalRead(PIN_COUT);<br />
<br />
Serial.print(" Got: sum=");<br />
Serial.print(measured_sum);<br />
Serial.print(" cout=");<br />
Serial.print(measured_cout);<br />
<br />
Serial.print(" Test:");<br />
if (measured_sum != sum || measured_cout != cout) {<br />
Serial.print(" FAIL");<br />
} else {<br />
Serial.print(" GOOD");<br />
}<br />
Serial.println();<br />
delay(500);<br />
}<br />
<br />
void loop() {<br />
Serial.println("Running test");<br />
test(0, 0, 0);<br />
test(0, 0, 1);<br />
test(0, 1, 0);<br />
test(0, 1, 1);<br />
test(1, 0, 0);<br />
test(1, 0, 1);<br />
test(1, 1, 0);<br />
test(1, 1, 1);<br />
}<br />
<br />
=Assignment: Debugging ALU design=<br />
<br />
Bob had to ship the ALU design to the hardware manufacturer by yesterday. The project manager is angry about missed deadline. Bob still hasn't figured out why the ALU is not working properly. Help Bob by figuring out what's the problem.<br />
<br />
If you're on Ubuntu install GHDL and GtkWave, otherwise simply use a school computer:<br />
<br />
sudo add-apt-repository ppa:pgavin/ghdl<br />
sudo apt-get update<br />
sudo apt-get install ghdl gtkwave git<br />
<br />
Clone the repository<br />
<br />
git clone https://github.com/laurivosandi/vhdl-exercise<br />
<br />
Use <code>make</code> to compile the components and run the testbench:<br />
<br />
cd path/to/vhdl-exercise<br />
make<br />
<br />
Expected output of the testbench:<br />
<br />
alu_testbench.vhd:77:9:@360ns:(report note): Finished testing addition operation of ALU<br />
alu_testbench.vhd:106:9:@1us:(report note): Finished testing subtraction operation of ALU<br />
alu_testbench.vhd:135:9:@1640ns:(report note): Finished testing NAND operation of ALU<br />
alu_testbench.vhd:166:9:@2280ns:(report note): Finished testing NOR operation of ALU<br />
<br />
However there are few bugs in <code>alu.vhd</code>, find the bugs and correct them. If this is your first experience with VHDL, take a look [http://lauri.vosandi.com/hdl/ here].<br />
<br />
=Assignment: Publishing your work=<br />
<br />
Deadline: 25. November<br />
<br />
* Clean up your Git repositories and send the URL of a repository that you've actively worked on (for example the one from Java course) to Lauri, but before check the following:<br />
** The repository should show changes you've made over at least few days.<br />
** The repository has to contain only plaintext files unless there is a really good reason not to (eg. images).<br />
** There has to be authorship information in the files.<br />
** Add <code>.gitignore</code> file to your GitHub repositories to ignore temporary files, see [https://git-scm.com/docs/gitignore Git docs] for more details.<br />
** Add [http://opensource.org/licenses LICENSE] file in the repository directory and commit the changes. LICENSE should answer to some important questions<br />
*** Who is the copyright holder?<br />
*** Under which conditions is redistribution permitted?<br />
** Add nicely formatted README file, see [https://help.github.com/articles/markdown-basics/ Markdown] (online editor [http://dillinger.io here]) and [http://sphinx-doc.org/rest.html reStructuredText] for more details. README should answer to several silly questions:<br />
*** What is the repository about?<br />
*** Who made it?<br />
*** How can the author be contacted? E-mail address, IRC chat channel on Freenode, Skype username?<br />
*** How can the code be used? What hardware is necessary? How should the user wire the circuit to make it work? Add images if necessary.<br />
*** What is the policy for including changes from third party developers?<br />
* There will be more details here<br />
<br />
=Extra points=<br />
<br />
Here you can claim extra credit points for various tasks, this is mostly to improve the quality of wiki.itcollege.ee.<br />
Once you have taken care of the task insert your name in the end of the line with corresponding date.<br />
<br />
* Expand [[Getting started with Ubuntu#Installing in VirtualBox]] section with highlighted screenshots of VirtualBox. Points: 1p<br />
* Create [[Claiming GitHub Student Developer Pack]] with screenshots how to add @itcollege.ee e-mail to your GitHub profile and claim [https://education.github.com/pack Student Developer Pack] Points: 2p</div>Vvelt