Diagrama de flujo
Sin título

Contenido del diagrama
Assembly Language
Assembly language programs are created out of three different classes of statements
The first class tell the processor what to do. These statements are called executable instructions, or instructions for short.
The second class of statements provides information to the assembler on various aspects of the assembly process. These instructions are called assembler directives or pseudo-op
The last class of statements , called macros, provide a sophisticated tex t substitution mecha nism. Macros are discussed in detail in the next chapter.
Assembly language statements are entered one per line in the source file. All three classes of the assembly language statements use the same format: [label] mnemoni c [operands ] [/comment
Now let us look at some sample assembly language statements. repeat: in c resul t /incremen t result by 1
The label repeat ca n be used to refer to this particular statement. The mnemonic inc indicates increment operation to be done on the data stored in memory at a location identified by result.
It is a good programming practice to use blank lines and spaces to improve the readability of assembly language programs
In particular, we almost always write labels on a separate line unless doing so destroys the program structure. Thus , our first example assembly language statement is written on two lines as repeat: inc resul t /incremen t result by 1
The NASM assembler provides several directives to reserve space for variables
Assembl y language instructions typically require one or more operands. These operands can be at different locations .
There are several different ways we can specify the location of the operands. These are referred to as the addressing modes
These addressing modes are sufficient to write simple but meaningful assembly language programs
Data Allocation
In high-level languages, allocation of storage space for variables is done indirectly by specifying the data types of each variable used in the program.
For example, in C, the following declarations allocate different amounts of storage space for each variable.
char response; /*allocates 1 bit */
int value; /*allocates 4 bit */
float total; /*allocates 4 bit */
double temp; /*allocates 8 bit */
These variable declarations not only specify the amount of storage required, but also indicate how the stored bit pattern should be interpreted
In the assembly language, allocation of storage space is done by the define assembler directive. The define directive can be used to reserve and initialize one or more bytes.
The general format of the storage allocation statement for initialized data is :
[variable-name] define-directive initial-value [,initial-value],.....
The square brackets indicate optiona l items . Th e variable-name i s used to identify the storage space allocated. The assembler associates an offset value for each variable name defined in the data segment.
Uninitialized Data
To reserve space for uninitialized data , we use RESB, RESW, and so on. Eac h reserve directive takes a single operand that specifies the number of units of space (bytes, words,...) to be reserved
There is a reserve directive for each define directive.
RESB Reserve a Byte
RESW Reserve a Word
RESD Reserve a Doubleword
RESQ Reserve a Quadword
REST Reserve Ten Bytes
Multiple Definitions
Assembly languag e programs typically contain several data definition statements . For example, look at the following assembly language program fragment :
sort DB 'Y' ; ASCII of y = 79H
value DW 2515 9 ; 25159D = 6247H
total DD 54280353 5 ; 542803535D = 205A864FH
When several dat a definition statements are used as above , the assembler allocate s contiguous memory for these variables. The memory layout for these three variables is

Multiple Initializations
The TIMES directive allows multiple initializations to the same value. Using TIMES, the marks array can be defined as: marks TIMES 8 DW 0
The TIMES directive is useful in defining arrays and tables.
Symbol Table
When we allocate storage space using a data definition directive, we usually associate a symbolic name to refer to it. The assembler, during the assembly process, assigns an offset value for each symbolic name.
For example, consider the following data definition statements:
.DATA
value DW 0
sum DD 0
marks TIMES 10 DW 0
message DB 'The grade is:' ,0 charl DB ?
As noted before, the assembler assigns contiguous memory space for the variables. The assembler also uses the same ordering of variables that is present in the source code
Where Are the Operands
Ther e are severa l way s to specify the location of the operands. These are called the addressing modes.
An operand required by an instruction may be in any one of the following locations:
- in a register internal to the processor;
-in the instruction itself;
- in main memory (usually in the data segment);
-at an I/O port .
Specification o f an operand that is in a register is called register addressing mode, while immediate addressing mode refers to specifying an operand that is part of the instruction. Severa l addressing modes are available to specify the location of an operand residing in memory.
Register Addressing Mode
In this addressing mode, processor's internal registers contain the data to be manipulated by the instruction. For example, the instruction
mov EAX,EB
requires two operands and both are in the processor registers. The syntax of the mov instruction is
mov destination,source
Immediate Addressing Mode
In this addressing mode, data is specified as part of the instruction itself. As a result, even though the data is in memory, it is located in the code segment, not in the data segment.
This addressing mode is typically used in instructions that require at least two data items to manipulate.
The remainder of the addressing modes we discuss here deal with operands that are located in the data segment. These are called the memory addressing modes
Direct Addressing Mode
Operands specified in a memory-addressing mode require access to the main memory, usually to the data segment. A s a result, they tend to be slower than either of the two previous addressing modes.
Recall that to locate a data item in the data segment, we need two components: the segment start address and an offset value within the segment. The start address of the segment is typically found in the DS register. Thus , various memory-addressing modes differ i n the way the offset value of the data is specified. The offset value is often called the effective address
Indirect Addressing Mode
I n this addressing mode , the offse t or
effective addres s of the data is in one of the general registers . Fo r this reason , this addressing mode is sometimes referred to as the register indirect addressing mode.
The indirect addressing mode is not required for variables having only a single element (e.g., response). Bu t for variables like tablel containin g several elements, the starting address of the data structure can be loaded into, say, the EBX register and then EBX acts as a pointer to an element in tablel. B y manipulating the contents of the EBX register, we can access different elements of table1.
Overview of Assembly Language Instructions
The MOV Instruction
We have already introduced the mov instruction, which requires two operands and has the syntax
mov destination,source
The data i s copied from source t o destination an d the source operan d remain s un changed. Bot h operands should be of the same size.
Simple Arithmetic Instructions
The instructin se t provides severa l instructions to perform simpl e arithmetic operations .
The INC and DEC Instructions
Thes e instruction s can be used to either incremen t or decrement the operands by one.
The inc (INCrement) instruction adds one to its operand
The dec (DECrement ) instruction subtracts one from its operand
Bot h instructions require a single operand. The operand can be either in a register or in memory. It does not make sense to use an immediate operand such as inc 55 or dec 109 .
The ADD Instruction
Th e add instruction can be used to add two 8, 16 - or 32-bit operands. The syntax is
add destination,source
As with the mov instruction, add can also take the five basic forms depending on how the two operands are specified. The semantics of the add instruction are destination = destination + sourc
The SUB and CMP Instructions
Th e sub (SUBtract) instruction can be used to subtract two 816- or 32-bit numbers. The syntax is sub destination,source
Conditional Execution
The instruction set has several branching and looping instructions to construct programs that require conditional execution.
Unconditional Jump
The unconditional jump instruction jmp, as its name implies , tells the processor that the next instruction to be executed is located at the label that is given as part of the instruction. has the form: jmp label
Conditional Jump
In conditional jump instructions, program execution is transferred to the target instruction only when the specified condition is satisfied. The format is j<cond> labe
TEC,Sede central, Fundamentos de organización de computadoras
Resumen #8 (Sivarama, caps. 9)
Jossy Mejia Vargas
Lunes 30 de octubre, 2 semestre, Esteban Arias Mendéz
Información
- Descripción
- Diagrama sobre Sin título, creado por Jossy Ivan Mejia Vargas el 31/10/2017.
- Creado por
- Jossy Ivan Mejia Vargas
- Visitas
- 0
- Valoración