You are on page 1of 11

ENGLISH III

PROGRAMMING IN ASSEMBLER LENGUAGE


COMPUTER SCIENCE

2012

PROGRAMMING IN ASSEMBLER LENGUAGE

Course: COMPUTER SCIENCE Subject: English 3 Members:

Barreto Valderrama Lizbeth Baltodano Rodrguez Byron Bryan Brenda Josselyn Bardales Lequerica Cam Urquizo Daniel Lzaro Mauricio Carlos Antonio Gutirrez Romero Fabio

English 3

Page 1

PROGRAMMING IN ASSEMBLER LENGUAGE

1. INTRODUCTION A program written in assembly language consists of a series of (mnemonic) processor instructions and meta-statements (known variously as directives, pseudo-instructions and pseudo-ops), comments and data. Assembly language instructions usually consist of an opcode mnemonic followed by a list of data, arguments or parameters. These are translated by an assembler into machine language instructions that can be loaded into memory and executed. An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices in which each statement corresponds to a single machine language instruction. An assembly language is specific to a certain computer architecture, in contrast to most high-level programming languages, which may be more portable. An assembler creates object code by translating assembly instruction mnemonics into opcodes, and by resolving symbolic names for memory locations and other entities. The use of symbolic references is a key feature of assemblers, saving tedious calculations and manual address updates after program modifications. The instruction set of a microprocessor is the set of binary inputs that produce actions defined during an instruction cycle. A set of instructions is for the microprocessor as well as a truth table is for a logic gate, a record of displacement or an adder circuit. Of course, the actions taken by a microprocessor with each instruction, are more complex than those performed by the aforementioned devices and gates. How to introduce a program in assembler on a computer? We have to translate it to hex or to binary. It can be done instruction by instruction "By hand" or, as in our case, through a program on a PC called EMU8086 and DEBUG. This is an example of programming in assembler: org 0 .model small .code mov ah,02h mov dl,30h int 21h end Disadvantages of Assembly: The assembly language (assembler) does not solve all programming problems. One is the tremendous difference between the microprocessor instruction set and the tasks the microprocessor to perform. The microprocessor instructions tend to do things as: adding contents of two registers, a shift the contents of one bit accumulator, or place a new value in the program counter (PC). Another drawback is the non-portability. Each microprocessor has its own set of instructions which is reflected in its internal architecture. A program written in assembler for 6809, will not run in 6502, Z80, 8080, or any microprocessor 16 or 32 bits. Even within the same family microcontrollers from Microchip Technology (PICs) are the same instructions. Each model has its own instruction set that differs in some other directions.

English 3

Page 2

PROGRAMMING IN ASSEMBLER LENGUAGE


The disadvantage of an assembly language program is that it requires a special program called an assembler, which is responsible for translating and alphanumeric mnemonics into machine

Example of assembly language in program DEBUG of windows xp

language. Also still need detailed knowledge of microprocessor architecture.

Assembler Features Delimiters: The fields are separated only by spaces and / or tabs. Never add other characters (commas, periods, etc). Do not use extra spaces, particularly after commas separating operands. (Eg movlw 5, w) Do not use delimiter characters (spaces and tabs) in names or labels. tags: The label is the first field in a line in assembly language and cannot exist. If a tag is present, the assembler is defined as the equivalent to the direction of Byte 1, corresponding to that instruction. This tag can be reused elsewhere but as an operand of an instruction. Mnemonic (operation code): The main task of the assembler is the translation of opcodes in mnemonic to binary equivalent. The assembler performs this task using a table as if we would do "by hand". The assembler must do more to translate the opcodes. should also determine how many operands the instruction requires and what type. This is a Little complex, some instructions (such as CLRW) have no operands, others (such as addition or jumps) are, while others (or skips bit manipulation) require two. Directives: English 3 Page 3

PROGRAMMING IN ASSEMBLER LENGUAGE


Some assembly language instructions are not translated directly to instructions machine language. These instructions are directives to the assembler, they assigned certain areas of program memory, defined symbols, designating areas of RAM for temporary data storage, data tables or placed in constant memory allow references to other programs. Policies are used as commands in the source code for a direct control or save time when assembling. The result of incorporating Directives can be seen in the *. LST, after joining the program.

number systems The number system we use every day is the decimal system, but this system is not suitable for the machines because the encoded information is treated as bits turned on or off, this form of coding leads to the need to know the computation positional to allow us to express a number in any base we need it. It is possible to represent a number in any base using the following formula: Where n is the digit position starting from right to left and numbered from zero. D is the digit on which we operate and B is the number base used. Convert binary numbers to decimal Working in assembly language we find the need to convert binary numbers, which is used by computers, the decimal system used by people. The binary system is based on only two conditions or states, either on (1) or off (0), therefore its base is two. For the conversion we use the positional value formula:

English 3

Page 4

PROGRAMMING IN ASSEMBLER LENGUAGE


For example, if we have the binary number 10011, took from right to left each digit and multiply by the base raised to the new position they occupy: Binary: 1 1 0 0 1 Decimal: 1 * 2 ^ 0 +1 * 2 ^ 1 +0 * 2 ^ 2 +0 * 2 ^ 3 +1 * 2 ^ 4 = 1 + 2 + 0 + 0 + 16 = 19 decimal. The ^ character is used in computing as a symbol of empowerment and the * character is used to represent multiplication. Convert decimal numbers to binary There are several methods for converting decimal numbers to binary, here is an analysis only. Naturally it is much easier conversion to a scientific calculator, but not always with her, so she should know at least a manual way to do it. The method used will be explained further division between the two, keeping the residue as the bit and the result as the following amount to divide. Take for example the decimal number 43. 43/2 = 21 and its residue is 1 21/2 = 10 and its residue is 1 10/2 = 5 and its residue is 0 5/2 = 2 and its residue is 1 2/2 = 1 and the remainder is 0 1/2 = 0 and its residue is 1 Putting the number of bottom-up we have the result in binary is 101011 Hexadecimal At the base we have 16 hexadecimal digits ranging from 0 to 9 and letters A through F (these letters represent the numbers 10 through 15). Therefore, we have 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F. Conversion between binary and hexadecimal numbering is simple. The first thing you do for a conversion of a binary number to hexadecimal is divided into groups of 4 bits, starting from right to left. In case the last group (the remaining most left) is less than 4 bits are filled with zeros missing. Taking as an example the binary number 101011 we divide into groups of 4 bits and we have: English 3 Page 5

PROGRAMMING IN ASSEMBLER LENGUAGE


10; 1011 Padding with zeros the last group (from left): 0010; 1011 We then take each group as a separate number and consider its value in decimal: 0010 = 2, 1011 = 11 But we can not represent this hexadecimal number as 211 because it would be a mistake, we have to replace all values greater than 9 per their respective representation in hexadecimal, so we get: 2BH (Where H is the hexadecimal base) To convert a hexadecimal number to binary is only necessary to reverse these steps: take the first digit is converted to hexadecimal and binary, and then the second, and so on until the number. ASCII code ASCII is usually pronounced "Aski" is an acronym for American Standard Code for Information Interchange. This code assigns the letters of the alphabet, the decimal digits 0 through 9 and several additional symbols a 7-bit binary number (Bit 8 getting in off state or 0). Thus each letter, digit or special character occupies one byte in memory of the computer. We can see that this method of data representation is very inefficient in the numerical aspect, because in binary format we just a single byte to represent numbers from 0 to 255, however with a byte ASCII code can represent only one digit. Because of this inefficiency, the ASCII code is primarily used in memory to represent text. BCD method BCD is an acronym for Binary Coded Decimal. This notation is used groups of 4 bits to represent each decimal digit from 0 to 9.With this method we can represent two digits per byte of information. She continues when this method is more convenient to represent numbers in memory compared to ASCII, still falls below the binary as a byte in the BCD method can only represent the digits 0 through 99, in contrast, binary format can represent all digits from 0 to 255. This format is used mainly to represent very large numbers in commercial applications because it facilitates transactions, thus avoiding rounding errors. English 3 Page 6

PROGRAMMING IN ASSEMBLER LENGUAGE


Historical perspective
Assembly languages date to the introduction of the stored-program computer. The EDSAC computer (1949) had an assembler called initial orders featuring one-letter mnemonics. Nathaniel Rochester wrote an assembler for an IBM 701 (1954). SOAP (Symbolic Optimal Assembly Program) (1955) was an assembly language for the IBM 650computer written by Stan Poley. Historically, a large number of programs have been written entirely in assembly language. Operating systems were entirely written in assembly language until the introduction of theBurroughs MCP (1961), which was written in ESPOL, an Algol dialect. Many commercial applications were written in assembly language as well, including a large amount of the IBM mainframe software written by large corporations. COBOL and FORTRAN eventually displaced much of this work, although a number of large organizations retained assembly-language application infrastructures well into the 90s. The Assembler for the VIC-20 was written by Don French and published by French Silk. At 1639 bytes in length, its author believes it is the smallest symbolic assembler ever written. The assembler supported the usual symbolic addressing and the definition of character strings or hex strings. It also allowed address expressions which could be combined with addition, subtraction, multiplication, division, logical AND, logical OR, and exponentiation operators. INTERNAL RECORDS PROCESSOR. The processor Register are used to control instruction execution, manage and provide memory address arithmetic ability. The Register are addressable by means of a name. Register CS (Code Segment). DOS stores the starting address of the code segment of a program in the CS register. This segment address, but an offset value in the registry instruction pointer (IP) indicates the address of an instruction that is sought for its implementation. Register DS (Data Segment). The starting address of a segment of program data is stored in records DS. In simple terms, this direction, but an offset value in a statement, generates a reference to the location of a specific byte in the data segment. Register SS (Stack Segment). The SS register allows placement in a stack memory for temporary storage of addresses and data. DOS stores the start address of the stack segment of a program you record SS. This segment address, but an offset value in the register stack pointer (SP) indicates the current word on the stack that is being addressed. Register ES (Extra Segment). Some operations with strings (character data) use the extra segment register to handle the memory addressing. In this context, the ES register is associated with the DI register (index). A program that requires the use of ES register can be initialized with an appropriate segment address.

Register of PURPOSE GENERAL. The general purpose registers AX, BX, CX and DX are the workhorses of the system. Are unique in the sense that it can address them as a word or as a part of a byte. The last byte of the left is the "high" and the last byte of the right is the "low". For example, the CX register consists of one part CH (high) and some Cl (low), and you can refer to any party by name. English 3 Page 7

PROGRAMMING IN ASSEMBLER LENGUAGE

AX register. The AX register, the main tank, is used for operations involving input / output and most arithmetic. For example, the instructions for multiply, divide and translate involve the use of AX. Also, some operations generate more efficient code if they relate to AX instead of the other records. BX register. The BX is known as the base register because it is the only general purpose register which can be index for indexed addressing. It is also common to use the BX for calculations. CX register, register counter, divided into CH and CL. - Used as a counter in loops (LOOP) in string operations (REP) and displacement (CL). DX register. The DX is known as l data record. Any input / output required use, and multiplication and division with large numbers assume the DX and AX working together. You can use the general purpose registers for addition and subtraction of numbers8, 16 or 32

English 3

Page 8

PROGRAMMING IN ASSEMBLER LENGUAGE

INSTRUCTION POINTER REGISTER The instruction pointer register (IP) of 16 bits contains the offset address of the next instruction is executed. The IP is associated with the CS register to the effect that theIP indicates the current instruction in the code segment that is currently running. POINTERS REGISTER. SP registers (stack pointer) and BP (base pointer) are associated with the SS register and enable the system to access data in the stack segment. SP register. The stack pointer is 16 bits associated with the SS register and provides an offset value that refers to the current word is being processed in the stack. BP register. The 16-bit BP facilitates the reference parameters, which are transmitted via data and address stack. INDEX REGISTER The SI and DI registers are available for indexed addressing and addition and subtraction. SI register. The index register 16-bit source is required by some string operations (character). In this context, the IF is associated with the DS register. The 80386 and later allow the use of an extended 32-bit register, the ESI. DI register. The destination index register is also required by some operations with strings. In this context, the DI is associated with the ES register.

FLAG REGISTER Of the 16 bits of the flags register, nine are common to the 8086 processor family, and serve to indicate the current state of the machine and the processing result. Many instructions that ask arithmetic comparisons and change the status of the flags, some of which instructions can perform tests to determine subsequent action. In summary, the common flag bits are as follows: OF (Overflow, overflow). Indicates overflow of a high order bit (left most) after an arithmetic operation. DF (direction). Designates the address to the left or right to move or compare strings. IF (interrupt). Indicates that an external interrupt, such as keyboard input, either processed or ignored. TF (trap). Allows operation of the processor in a step mode. The program debuggers, such as DEBUG, activate this flag so that you can move forward in executing one instruction at a time, to examine the effect of that instruction on the memory registers. SF (sign). Contains the resulting sign of an arithmetic operation (0 = positive and 1 = negative). ZF (zero). Indicates the result of an arithmetic or comparison (0 = result different from zero and 1 = result equal to zero). AF (auxiliary carry). Contains an external carry a data bit 3 of 8 bits for specialized arithmetic. PF (parity). Even or odd parity indicates an operation on data from low-order 8 bits (rightmost). English 3 Page 9

PROGRAMMING IN ASSEMBLER LENGUAGE

English 3

Page 10

You might also like