Chapter 1

Definitions

Assembler - converts source (assembly) code into machine language
Linker - combines multiple object files created by assembler into one executable file
Debugger - allows stepping through a running program to examine registers and memory
MASM Programs:

One-to-one relation

One assembly instruction is converted into one machine instruction
High-level languages have one-to-many relation, where one HLL instruction can be expanded into multiple machine instructions

High-Level Languages - (C++, Python). Have 1-to-many relation
Registers - storage in CPU holding intermediate results of operations

Assembly Usage

Assembly language is NOT portable
Each family of processors has its own version of assembly language
Almost every high-level language is portable

Good Assembly Use-Cases

Virtual Machine Concept

Computer by itsself can only execute machine code. (L0)
For humans, it's not understandable, so we write higher-level code (L2)
Sometimes, that is not flexible enough, so we create higher levels (L3)

For computers to understand L1 code, we have two possibilities:

We can also turn this concept by using Virtual Machines instead of languages
Higher-level VM turns its code into one understandable by VM one level below
Each VM can be either software or hardware-based
rM drawing 2026-02-21-20.41.02.png250

Real computer situation

rM drawing 2026-02-21-20.45.24.png500
Instruction Set Architecture (level 2) - set of basic operations (add, move, multiply) executed directly by hardware or by microprocessor embedded program - microprogram

Data Representation

Numeric Systems
Binary Integers

Sequence of 16 bits, starting from the Most Significant bit (MSb) to the Least Significant bit (LSb)

0MSb151 1 0 1 0 1 18 1 0 1 0 0 0 11LSb0

Binary integers can be signed or unsigned (positive by default)
Bit position values: starting from LSb (i=0), each bit has an increasing value of 2i
rM drawing 2026-02-21-20.54.52.png300

Binary to Decimal Conversion

We multiply value of each bit (0/1) by the bit's weight, and add all of the products together

100112=124+023+022+121+120=16+2+1=1910
Decimal to Binary Conversion

We divide the decimal by base (2) and save the remainder starting from LSB upwards

37/2=18 r. 118/2=9 r. 09/2=4 r. 110010124/2=2 r. 02/2=1 r. 01/2=0 r. 1
Binary Addition
0+0=00+1=11+0=11+1=10

To add two binary numbers, we add bits of the same weight, and (if applicable), carry 1 into next, higher bit

 0 1 1 1 0 1 1 11100111011111+011110+30=10100141
Binary Subtraction
010100013001117001106

bit 0 is easy - 11=0
For bit 1, we have to borrow 1 from higher bit (2), so it turns into 101=1, and for bit 2, 0 is left

A simple approach would be to take a Two's Complement of the second value, and turn the problem from 137 into 13+(7) which is easy to calculate and can be done on the same circuit

Integer Storage Sizes

Byte - 8 bits
Word - 2 bytes, 16 bits
Double Word - 4 bytes, 32 bits
Quad Word - 8 bytes, 64 bits
Double Quad Word - 16 bytes, 128 bits

Signed Binary Integers

We use MSb as the SIGN bit
0 - positive
1 - negative

Hexadecimal numbers

Easier to read than binary for large numbers
Digits are 0F with values 015

1 0001 6 0110 A 1010 7 0111 9 1001 C 1100 

One hex digit is equal to 4 bits

Hexadecimal to Decimal Conversion

Same method as for bin-dec. Multiply each digit by its weight (16i)

3BA4=3163+11162+A161+4160=12288+2816+160+4=15268
Decimal to Hexadecimal Conversion

Again, exactly the same process as for dec-bin. Divide by base (16) and take the remainder

422/16=26 r. 626/16=1 r. 101A61/16=0 r. 1
Hexadecimal Addition

Works in the same way as binary, just with base 16

61A2+49AB3C
Two's Complement

Most used notation of numbers, allowing for easy addition with negative numbers. Addition is exactly the same as Binary Addition
Additionally, gets rid of negative-zero problem
To get a negative complement of a number, we have to use formula

x=x¯+10010110044100110001041. invert the number11010011011001112. add 1 to the invert110101004401101000104
Hexadecimal Two's Complement

Same process. Taking complement of a hex digit x means taking 15x

4A92B56D+1B56EF14C0EB3+1OEB4
Signed Binary to Decimal Conversion

If the SIGN bit is 0 (positive number) the number is converted as unsigned binary
If the number is negative (MSB=1) we calculate the positive Two's Complement equivalent, and then convert that to decimal

Minimum and Maximum Values

Signed Byte - [27,271]
Signed Word - [215,2151]
Signed Double Word - [231,2311]
Signed Quad Word - [263,2631]

Large Data Sizes

1 kilobyte = 210 = 1024B
1 megabyte = 220 = 1024kB
1 gigabyte = 230 = 1024MB
1 terabyte = 240 = 1024GB
1 petabyte = 250 = 1024TB
1 exabyte = 260 = 1024PB
1 zettabyte = 270 = 1024EB
1 yottabyte = 280 = 1024ZB

Terminology for Numeric Data Representation

01000001 as an integer is 65, as a character - A
To differentiate, we introduce naming:

Storing characters

To represent a character, computers use character sets, where each value corresponds to one character
The most basic, 7-bit set is called ASCII (American Standard Code for Information Interchange)
Because ASCII uses only 7 bits, the additional space is used for proprietary sets (i.e. Greek letters on early IBMs)

ANSI (American National Standards Institute) defines 8-bit, 256 character set, with first 128 being letters and symbols on standard US keyboard, next 128 for international letters, currency symbols and fractions

Today, we need to store lots more of characters, and we do it in UNICODE standard.

ASCII String

Sequence of 1 or more characters is called a string
String ABC123 is stored as 41h,42h,43h,31h,32h,33h
Most systems require a null-terminated strings ('\0') as an indicator of the end of the string

ASCII Control Characters

Codes 031 are set for control charactes, which are indicators for the system
Most common:

Binary-Coded Decimal BCD Numbers
Unpacked BCD

One decimal digit is stored in one byte

123401, 02, 03, 04hex bytess

If the order is equal to decimal (high-order digits first) - Big-Endian Order
If the order is opposite to decimal - Little-Endian Order

Packed BCD

Two digits are stored in one byte

123412, 34hex bytes

This saves 2× space, but takes more time to unpack and display

Boolean expressions

Boolean algebra defies expressions on values TRUE or FALSE
Basic operations:

NOTANDORAA¯1001ABAB000010100111ABAB000011101111
Multiplexer
(YS)(XS¯)

rM drawing 2026-02-23-11.46.11.png250