Professional Documents
Culture Documents
What Is Assembly Language?: Introduction To The GNU/Linux Assembler and Linker For Intel Pentium Processors
What Is Assembly Language?: Introduction To The GNU/Linux Assembler and Linker For Intel Pentium Processors
High-Level Language
Most programming nowdays is done using
so-called high-level languages (such as
FORTRAN, BASIC, COBOL, PASCAL, C,
C++, JAVA, SCHEME, Lisp, ADA, etc.)
These languages deliberately hide from
a programmer many details concerning
HOW his problem actually will be solved
by the underlying computing machinery
LET X = 4
LET Y = 5
LET Z = X + Y
PRINT X, +, Y, =, Z
END
Output:
4+5=9
The C language
Other high-level languages do require a small
amount of awareness by the program-author of
how a computation is going to be processed
For example, that:
- the main program will get linked with a
library of other special-purpose subroutines
- instructions and data will get placed into
separate sections of the machines memory
- variables and constants get treated differently
- data items have specific space requirements
int
int
// initialized variables
// unitialized variable
x = 4, y = 5;
z;
int main()
{
z = x + y;
printf( %d + %d = %d \n, x, y, z );
}
Example of machine-language
Heres what a program-fragment looks like:
10100001 10111100 10010011 00000100
00001000 00000011 00000101 11000000
10010011 00000100 00001000 10100011
11000000 10010100 00000100 00001000
It means:
z = x + y;
Incomprehensible?
Though possible, it is extremely difficult,
tedious (and error-prone) for humans to
read and write raw machine-language
When unavoidable, a special notation can
help (called hexadecimal representation):
A1 BC 93 04 08
03 05 C0 93 04 08
A3 C0 94 04 08
Main
Memory
system bus
I/O
device
I/O
device
I/O
device
I/O
device
Temporary
Storage
(STACK)
ESP
Program
Variables
(DATA)
Program
Instructions
(TEXT)
EAX
EAX
EAX
EAX
EIP
device_id, 1
sys_write, 4
sys_exit, 0
.data
4
5
0
%d + %d = %d \n
80
0
.text
_start:
# comment: assign z = x + y
movl
x, %eax
addl
y, %eax
movl
%eax, z
demo.o
assembly
program
object
module
demo
linking
the
executable
program
Summary
High-level programming (offers easy and
speedy real-world problem-solving)
Low-level programming (offers knowledge
and power in utilizing machine capabilities)
High-level language hides lots of details
Low-level language reveals the workings
High-level programs: readily portable
Low-level programs: tied to specific CPU
In-class exercise #1
Download the source-file for demo1, and
compile it using the GNU C compiler gcc:
$ gcc demo1.c -o demo1
Website: http://cs.usfca.edu/~cruse/cs210/
Execute this compiled applocation using:
$ ./demo1
In-class exercise #2
Download the two source-files needed for our
demo2 application (i.e., demo2.s and
sprintf.s), and assemble them using:
$ as demo2.s -o demo2.o
$ as sprintf.s -o sprintf.o
Link them using:
$ ld demo2.o sprintf.o -o demo2
And execute this application using: $ ./demo2
In-class exercise #3
Use your favorite text-editor (e.g., vi) to
modify the demo2.s source-file, by using
different initialization-values for x and y
Reassemble your modified demo2.s file,
and re-link it with the sprintf.o object-file
Run the modified demo2 application, and
see if it prints out a result that is correct