Lecture%2023%20-%20Assembler%20Fundamentals - Ananda...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Ananda Gunawardena Lecture 23 Assembler Fundamentals All programs written in a high-level language like C are converted into machine language so they can be executed by the underlying hardware. However, the process of converting high level source code to machine language goes through several intermediate steps. One of them is the conversion of source code into assembly language instructions native to the hardware. Converted assembly code is optimized by the C compiler so they can be executed more efficiently by the hardware. Assembly code from high level code is then assembled using a program called “assembler” into object code which then in turn linked up with supporting library code to generate the executable code . We know that it is difficult to program in machine language, and therefore assembly language provides an intermediate step where programs can be written using English like instructions using direct instructions that can manipulate hardware. These assembly instructions closely mimic how they are carried out by the hardware. A typical assembly code instruction contains an operation code (opcode), an English description of what operation a hardware is supposed to perform and operands to support the operation(if any). For example, an assembly instruction to add two “registers” and place the answer in another register may look like add r1,r2,r3 where add is the operations code (opcode) for the assembly instruction. We note that assembly instructions may vary from architecture to architecture. A collection of assembly language instructions with other operating systems directives, form a complete assembly language program. An example of an assembly program in i686 is given by (man uname) #listing 1 .global main main: movl $20, %eax ret The above program is a simple program that moves the content 20 to a register eax. The $ identifies immediate values and % identify a register. Assuming that above program is in a file name first.s, the program can be compiled with gcc compiler and generate a binary executable file called a.out by using h gcc first.s h ./a.out
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
The generic process of generating the executable from assembly code is shown below. Assembler linker High level language instructions and assembly instructions are written using readable text. Assembly language instructions are architecture dependent. For example, Intel family of processors may understand one type of assembly language instructions. The opcode of an assembly language instruction may change from architecture to architecture. However, opcodes like
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 7

Lecture%2023%20-%20Assembler%20Fundamentals - Ananda...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online