Assembly
Assembly
CPU
PC ALU
I/O bus
Expansion slots for
other devices such
USB Graphics Disk as network adapters
controller adapter controller
How Simple
hello executable
Disk stored on disk
Figure 1.6 Loading the executable from disk into main memory.
Helloworld.c CPU
Register file
works PC ALU
“hello, world\n”
I/O Main
Bus interface
bridge memory hello code
I/O bus
Expansion slots for
other devices such
USB Graphics Disk as network adapters
controller adapter controller
Figure 1.7 Writing the output string from memory to the display.
Amdahl’s law.
α=0.6
system that initially consumed 60% of the k=3
time (α=0.6) is sped up by a factor of 3 1/[0.4 + 0.6/3] = 1.67×
(k=3 )
Representing and Manipulating Information
This chapter explains how numbers and other forms of data represented on a comptuer. and
their arithmetic releates to integer and real numbers
1010111001001001
0x173A4C
3210
Hexadecimal calculation
Decimal to Hex
429496710
Bit Size (Data Size)
• 32 bits word size (4 * 109 bytes) – 4 GB of virtual address space
• 64 bits word size (1.84 * 1019 bytes) – 16 exabytes of virtual address space
0x0027C8F8
27C8F8
0x4A1F23E0
Boolean Algebra
Unlike bitwise logical operation (&&, ||, !) represent 0 (0x00 – False) and (0x01 – True)
Shift Operations
Command
gcc –Og –S byetesex bytesex.c (assembly code only)
gcc –Og -c bytesex.c (both object code and assembly code)
-Og Follow Original
code level
-S Assembly code
-o Object code
bytesex Output file name
bytesex Execute file
Data Format
Most instructions have one or more operands specifying the source values to use in performing an
operation and the destination location into which to place the result
Text book Exercises
Exercises
9(%rax, %rdx)
260(%rcx, %rdx)
Data movement instruction
x86 Registers
Stack <data structure> – keep local
variables on memory
First in Last Out
label definitoin
lea edi, [ebx+4*esi] the quantity EBX+4*ESI is placed in EDI
lea eax, [var] the value in var is placed in EAX.
lea eax, [val] the value val is placed in EAX
Data movement instructions
label definitoin
inc <reg> 1. Increment
inc <mem> 2. decrement
dec <reg>
dec <mem>
INC COUNT 1. Increment the memory variable COUNT
dec eax 2. subtract one from the contents of EAX.
-> Golbal symbols – global variables and non static function data
-> local symbols – static attributes global variables and static function data
<in c programming> if global variables are declared with static in the module that
mean it can only be available in module level not into global level (One way to
hide value by programmer>
• Linker doesn’t store information of local variables data. Local variable data are store in Stack.
Exercises