TECHNOLOGY 

Published on
KembaraXtra – Computer Terms – * :
The asterisk, also called the star symbol, is widely used in various computing environments. In programming, it often means multiplication. For example, 5 * 3 equals 15. In operating systems like Windows and MS-DOS, it works as a wildcard character to replace one or more characters in a filename. For instance, *.txt would refer to all text files. In C and C++ programming, the asterisk is also used for pointer operations—it helps retrieve the actual value stored at a memory location pointed to by a pointer variable.


Picture
Published on
KembaraXtra – Computer Terms – . means:
This symbol combination is a wildcard pattern used mainly in command-line environments like MS-DOS and Windows. It represents every possible file name and every possible extension. For example, *.* could be used to copy, move, or delete all files in a directory, regardless of their names or file types. It is especially useful when performing actions on many files at once.


Picture
Published on
KembaraXtra – Computer Terms – .. means:
Two dots used together in file system navigation refer to the parent directory—the folder above the current one in the directory structure. This is a common shorthand used in UNIX and MS-DOS. A single dot (.) refers to the current directory. Together, .. is essential for moving up levels in command-line interfaces.


Picture
Published on

KembaraXtra - Computer Science: Variables in Programming

I. What is a Variable?

Definition: A named storage location in memory.

Purpose:
• Provides a way to access data at a specific memory address using a name.
• Abstracts away the need to manage specific memory addresses directly.

Properties of Variables:
• Name: The identifier used to refer to the variable (e.g., points, age).
• Type: Specifies the kind of data the variable can hold (e.g., integer, string).
• Value: The actual data stored in the variable's memory location (e.g., 27, 2020).
• Address: The memory location where the variable's value is stored.
• Scope: The region of the program where the variable can be accessed.

II. Variables in C

Declaration and Assignment:
int points = 27;
• int: Declares the variable points to be of type integer.
• points: The name of the variable.
• = 27: Assigns the integer value 27 to the variable points.

Type Specificity:
• C is a statically typed language.
• Once a variable is declared with a specific type (e.g., int), it can only hold values of that type. Attempting to assign a value of a different type will result in a compilation error.

Memory Allocation:
• The compiler allocates memory for the variable based on its type.
• Example: int typically occupies 4 bytes (32 bits) in modern C compilers.
• Variables declared sequentially are often stored contiguously in memory (but this isn't guaranteed by the C standard).

Changing Variable Values:
points = 31; // Changing the value of the points variable
• The type does not need to be respecified.

III. Variables in Python

Dynamic Typing:
• Python is a dynamically typed language.
• You do not explicitly declare the type of a variable. The type is inferred at runtime based on the assigned value.

Declaration and Assignment:
age = 22
• Creates a variable named age and assigns it the integer value 22.
• Python infers the type of age to be an integer.

Type Flexibility:
age = 22
age = 'twenty-two'
• First, age refers to an integer value (22).
• Then, age is reassigned to refer to a string value ('twenty-two').

Values have Types, Not Variables:
• The value to which a Python variable refers has a type.
• The variable itself doesn't have a fixed type.
• When you assign a new value to a variable, you are binding the variable to a new value (which may have a different type).

Key Difference from C: C variables have a fixed type, while Python variables do not.

Picture
Published on

KembaraXtra - Computer Science: Comments in Programming Languages - A Study Guide

What are Comments?

Definition: Text added to source code to explain or provide context about the code.

Purpose:
• Improve code readability for other developers (or your future self).
• Explain the logic behind complex code sections.
• Provide usage examples.
• Document code functionality.

Impact on Execution: Comments are ignored by the compiler/interpreter. They do not affect how the program runs.

C-Style Comments

Multiline Comments:
• Syntax: Enclosed within /* and */
• Example:
/*
  This is a C-style comment.
  It can span multiple lines.
*/

Single-Line Comments:
• Syntax: Begins with //
• Note: Originally introduced in C++ and later adopted by C.
• Example:
// This is a single-line C comment.

Python Comments

Single-Line Comments:
• Syntax: Begins with #
• Example:
# This is a comment in Python.

Multiline Comments:
• No Dedicated Syntax: Python doesn't have a built-in multiline comment syntax.
• Workaround: Use multiple single-line comments.
# This is the first line of a multiline comment.
# This is the second line.
# And this is the third line.

Picture
Published on
KembaraXtra-Case Law-C and Python: High-Level Programming
I. Introduction
  • The best way to learn high-level programming is by examining programming languages and writing programs.
  • This study guide focuses on C and Python.
  • Both are powerful and useful languages that illustrate common programming functionalities with different approaches.
II. The C Programming Language
  • History: Dates back to the early 1970s; initially used to write Unix OS.
  • Level: High-level, but relatively close to machine code.
  • Strengths:
    • Good for operating system development and hardware interfacing.
    • High-performance applications (e.g., games).
    • Useful for educational purposes to show the mapping between low-level and high-level concepts.
  • Weaknesses:
    • Complex.
    • Few safeguards against programmer errors.
  • Related Language: C++ (developed in the 1980s) is an updated version of C.
III. The Python Programming Language
  • History: Initially released in the 1990s.
  • Level: High-level, further removed from hardware than C.
  • Strengths:
    • Easy to read and simple for beginners.
    • Suitable for complex software projects.
    • "Batteries included" philosophy: Includes a comprehensive standard library.
    • Good for teaching programming concepts.
IV. Common Elements in High-Level Programming Languages
  • High-level languages provide abstractions of CPU instructions.
  • CPUs provide instructions for:
    • Memory access
    • Math and logic operations
    • Control of program flow
  • The goal is to familiarize yourself with common programming ideas, not to become proficient in a specific language.



Picture
Published on
KembaraXtra-Computer Science-High-Level Programming
1. The Need for High-Level Languages
  • Problem with Assembly Language:
    • Time-consuming and error-prone.
    • Difficult to maintain.
    • CPU architecture-specific (not portable).
  • Solution: High-Level Languages
    • More human-readable syntax.
    • CPU-independent.
    • Promotes portability.
2. Compilation
  • Compiler: A program that translates high-level language code into machine code.
  • Portability: High-level languages allow you to compile code for different processors with minimal changes.
  • Output: The compiler produces an object file containing machine code for a specific processor.
3. Linking
  • Object Files: The output of compilation, but not directly executable.
  • Linker: A program that combines one or more object files into a single executable file.
    • Resolves dependencies and includes necessary code libraries.
    • Prepares the executable for the operating system to run.
4. The Build Process
  • Building Software: The complete process of converting source code to an executable file, encompassing compilation and linking.
  • Common Usage: Developers often say "compiling" to mean the entire build process.
  • Automation: Compilers often automatically invoke the linker, which obscures the linking step.



Picture
Published on

KembaraXtra-Computer Science - Calculating Factorial in Machine Code

1. What is a Factorial?
• The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n.
• Example: 4! = 4 × 3 × 2 × 1 = 24

2. ARM Machine Code for Factorial Calculation
• The following code calculates the factorial of an integer n.
• Initial condition: n is stored in register r0.
• Final condition: n! (the factorial of n) is stored in register r0.

2.1. Machine Code in Memory
• Machine code is loaded into memory as hexadecimal values. Each instruction is 4 bytes (32 bits) long.

Address     Data
0001007c    e2503001
00010080    da000002
00010084    e0000093
00010088    e2533001
0001008c    1afffffc

2.2. Assembly Language Equivalent
• Disassembling the machine code gives the corresponding assembly language instructions:

Address     Data        Assembly
0001007c    e2503001    subs r3, r0, #1
00010080    da000002    ble 0x10090
00010084    e0000093    mul r0, r3, r0
00010088    e2533001    subs r3, r3, #1
0001008c    1afffffc    bne 0x10084
00010090                ---

• The code starts at address 0001007c and ends (factorial calculation) at address 00010090.

3. ARM Instructions Explained

Instruction       Details
subs Rd, Rn, #Const   Subtract: Subtracts the constant value Const from the value stored in register Rn and stores the result in register Rd. Rd = Rn - Const. Also, subs affects the status register (used for conditional branching).
mul Rd, Rn, Rm        Multiply: Multiplies the value stored in register Rn by the value stored in register Rm and stores the result in register Rd. Rd = Rn × Rm
ble Addr              Branch if less than or equal: If the previous operation's result was ≤ 0, jump to address Addr.
bne Addr              Branch if not equal: If the previous operation's result was not 0, jump to address Addr.

4. Branching and the Status Register
• ARM processors use a status register to track the results of operations.
• Specific bits in the status register (flags) indicate conditions like negative result, zero result, etc.
• Instructions like subs update the status flags.
• Branch instructions (e.g., ble, bne) check the status flags to determine whether to jump or continue.

5. Exercise: Understanding the Factorial Program
• Goal: Trace the execution of the assembly code to calculate the factorial of 4.
• Initial condition: r0 = 4
• Expected final result: r0 = 24

Procedure:
i. Create a table to track the values of r0 and r3 before and after each instruction.
ii. Execute each instruction sequentially, updating the register values accordingly.
iii. Pay attention to how the subs instructions affect the status flags and how the branch instructions (ble, bne) use these flags to control the flow of execution.
iv. Stop when the program reaches address 00010090.
v. Verify that r0 contains the value 24.

Assembly Code:

Address     Assembly
0001007c    subs r3, r0, #1
00010080    ble 0x10090
00010084    mul r0, r3, r0
00010088    subs r3, r3, #1
0001008c    bne 0x10084
00010090    ---

6. Additional Projects (See Text for Details)
• Project #12: Assemble the factorial code and examine it while it runs.
• Project #13: Learn additional approaches for examining machine code.

Picture
Published on
KembaraXtra-Computer Science- Machine Instruction
ARM Processor Example: Moving the Number 4 into Register r7
  • Context: The example focuses on an ARM processor instruction, commonly found in smartphones.
  • Instruction Goal: The instruction moves the number 4 into the r7 register. Registers are small storage locations within the CPU.
  • Binary Representation: The instruction in binary form is: 11100011101000000111000000000100
  • Decoding the Binary:
    • Condition (1110): Specifies when the instruction is executed. 1110 means it's always executed (not conditional).
    • Immediate Bit (1): Indicates whether the instruction uses a direct value (immediate value) or a value from another register. 1 means it uses an immediate value (the number 4 in this case).
    • Opcode (mov): Represents the operation to be performed. mov means "move" data.
    • Destination Register (0111): Indicates the register where the value will be moved. 0111 is binary for 7, representing register r7.
    • Immediate Value (00000100): The actual value to be moved. 00000100 is binary for 4.
    • Summary: The binary translates to: "Move the number 4 into register r7."
Hexadecimal Representation
  • Purpose: A more compact and readable representation than binary.
  • Example: The same instruction in hexadecimal is: e3a07004
Assembly Language Representation
  • Definition: A programming language where each statement directly represents a machine language instruction. Each machine language has its assembly language (e.g., x86 assembly, ARM assembly).
  • Structure: Consists of a mnemonic (human-readable opcode) and operands (registers, values).
  • Mnemonic Example: mov is the mnemonic for the "move" operation.
  • Example Instruction: The same instruction in ARM assembly language is: mov r7, #4
  • Advantages: More readable and understandable for humans.
  • Important Note: CPUs only execute binary code. Assembly language is a human convenience.
Assembler
  • Function: A program that translates assembly language statements into machine code (binary).
  • Process:
    1. An assembly language text file (source code) is input.
    2. The assembler translates it into a binary object file (machine code).



Picture
Published on
KembaraXtra-Case Law-Software Terms Defined
I. Key Definitions:
  • Software: Instructions that tell a computer what to do. Contrast: Hardware (physical components).
  • Program: An ordered set of software instructions that accomplishes a task. Related term: Programming (writing such programs).
  • Application: Often used synonymously with "program", but implies direct interaction with humans. Can consist of multiple programs. Related term: App (modern usage, connotations to be covered later).
  • Code (Computer Code): Another name for a set of software instructions.
  • Source Code: The text of a program as originally written by developers. Written in a higher-level programming language. Requires additional steps before execution.
  • Machine Code: Software in binary machine language instructions that a CPU can directly execute.
  • Machine Language: The set of instructions a specific CPU architecture understands.
II. Relationship between Code Types
  • Source Code --> Machine Code: Source code, written by developers, must be converted into machine code for the CPU to execute.
  • Universal Conversion: Regardless of the initial programming language or technologies used, all programs ultimately become a series of 0s and 1s representing CPU instructions.
III. Core Concept
  • "It's Just Code": Even complex software, when examined at its most fundamental level, is simply a series of instructions (0s and 1s) that a CPU interprets.
IV. Analogy
  • Human Language vs. Machine Language:
    • Vocabulary words are like CPU instructions.
    • Sentences formed from words are like programs formed from instructions. Both convey meaning.



Picture