Basic comp scie vocab (again)

okay I'm rewriting this blog post, I originally had 15 words with definitions but I'll only use 4 now because I'm tired and my laptop is gonna die ahhh 


 1. Variable

A variable is a storage location in a computer program, which has a name and can hold a value. This value can change (hence the term "variable"). For example, in the statement `x = 5`, `x` is a variable that stores the value `5`.


2. Data Type

A data type defines the kind of data that can be stored and manipulated within a program. Common data types include:

   - Integer (int): Represents whole numbers (e.g., `5`, `-3`).

   - Float: Represents decimal numbers (e.g., `3.14`, `-2.0`).

   - String (str): Represents sequences of characters (e.g., `"hello"`, `"123"`).

   - Boolean (bool): Represents truth values, either `True` or `False`.


3. Function

A function is a block of code designed to perform a particular task. Functions take inputs (called arguments or parameters), process them, and return an output. For example, in Python, `def add(a, b): return a + b` defines a function that adds two numbers.


4. Loop

A loop is a programming construct that repeats a block of code as long as a specified condition is true. The two main types of loops are:

   - For Loop: Iterates over a sequence (like a list or range) a specific number of times.

   - While Loop: Repeats as long as a condition remains true.

---------------


okay my laptop is gonna die any sec now but yes gonna rework this blog post tomorrow :,,)


3 Kudos

Comments

Displaying 2 of 2 comments ( View all | Add Comment )

sparky

sparky's profile picture

Addendum:
Its fun looking at programming concepts in assembler, since it can give you some idea of how compilers interpret the abstractions given by modern programming langs and hand it off to the computer. Though I will say I am just going off the dome, its late and my assembler is a bit rusty, so please excuse any mistakes.

Variables:
So when it comes to variables, you dont define variables via their type, rather you allocate bytes in memory, and put contents in those bytes.
~~~
section .data
char DB "h" ;Declares a character by allocating 1 byte (DB), and assigning "h" to it.
int DD 42069 ;Here we allocated a doubleword (4bytes) and assigned it 42069. back in da day, compilers had ints as 2 bytes (word), but modern compilers use 4 bytes.
float DD 3.14159 ;A float is a Quad Word, 8 bytes.

Booleans are different. Since booleans are abstractions, you just use Boolean operators, like AND, OR, XOR, etc to do boolean maths. You can though, set constants in Assembler that map to true or false you call later. You can do this via the EQU operator

TRUE equ 1
FALSE equ 0

and then compare them via CMP instruction, depending on what you are doing.

which brings us to conditionals, as you could imagine, if else, and loops are just... abstractions. You can accomplish these by using Jumps and compares.

So if you wanna do a if statement:

TRUE DD 1 ;defining true and false consts
FALSE DD 0
mov RAX, 0 ;moves 0 into RAX, you could have a variable that equals 0 as well, and move that into RAX, which is a register. Basically stores data temporarily to move it around.
CMP RAX, 0 ; compares contents of RAX to 0, it does this via subtraction. which RAX = 0, means that comparing 0 to 0 = YAY!!!

You can use this for loops, and if else, or switch statements (learn switch statements now, they will save your life a lot early on). If you have a loop you want to run 10 times, you can have a register that gets added to once every time a loop runs and is compared until its 10.

0x1 mov RAX, 0 ;Moves 0 into RAX
0x2 add RAX, 1 ;Add 1 to RAX. This can also be accomplished with INC (increment) "INC RAX" Increments RAX by 1. Just wanted to show off the basic math ADD, theres also SUB, DIV, MUL, etc.
*some code you want looped
0x29 cmp RAX, 10 ;Compared RAX to 10
0x30 jle 0x1 ;JLE jumps to less than or equal to, so as soon as its greater than 10, the "counter" will go back to line 0x1



This wasnt really meant to be a tutorial in assembly, but i am working on something of that nature. More so about programming, and computers science from silicon to cloud. im probably gonna name it technomancy101 or something.

Nonetheless the value of learning ASM cant be overstated, it will help you write better code by understanding how code is seen by the compiler. You also might find it interesting to know, and maybe you can notice, that this isnt exactly machine code, it isnt binary. There is a few more steps between assembly and actual firing of transistors within the CPU. One of my favorite is uOps. Basically breaking down these instructions into the actual CISC instructions, (check out RISC vs CISC, and the RISC vs CISC wars). These have crazy cool features in terms of hyper optimization of code, just understanding modern processors, and security (there have been a few examples of exploiting or backdooring microcode, basically malware in the CPU itself EEEEEEEEEEEEEEE).

Sorry if formatting is bad, this text box isnt meant for this, nonetheless if you have questions feel free to shoot, i know i may have skimmed over a lot of stuff, and not properly clarified things. alas it is late and i am tired, and will sleep soon. anyways

COMPUTERS ARE COOL YO!!!


Report Comment

cinnamonlamb

cinnamonlamb's profile picture

this really gives logic and algorithms subject vibes


Report Comment