Lecture 2 Assembly Language Programming 2024-2025 PDF
Document Details
2024
Eman Ahmed Badry
Tags
Summary
These lecture notes cover assembly language programming, including topics such as high-level languages, machine code, and interrupts. Different instruction types and how they are used are detailed.
Full Transcript
Dr. Eng. / Eman Ahmed Badry 2024-2025 Most programming today is done in a high-level language, which can run on various machines (portable). It is easier to write and maintain high-level programs. Assembly language was developed to make a simpler interface between the m...
Dr. Eng. / Eman Ahmed Badry 2024-2025 Most programming today is done in a high-level language, which can run on various machines (portable). It is easier to write and maintain high-level programs. Assembly language was developed to make a simpler interface between the machine and the programmer. Assembly language is useful today for many operations because it executes fast and efficiently, but it must be written for a specific processor (non-portable) and takes more time to write programs. Early computers were programmed in machine language, which was the only instructions the computer could execute. Machine language is tedious to write and prone to errors. Cross-assembler is a program that translates an assembly language program for one type of microprocessor to an assembly language for another type of microprocessor. High-level language Closer to human language Portable Assembly language English-like terms representing binary code Machine dependent Machine language Binary code (1s and 0s) Machine dependent Computer hardwar e (the “machine”) CPU Memory (RAM, ROM) Disk drives Input/Output High-level languages can run on any machine; the source code is converted to machine code by a compiler. (In some cases an interpreter is used; it converts source code line-by-line.) Assembly language must written for the specific processor it will be used on and the programmer must understand the register structure of the processor. An assembler converts the source code to the machine code. A given high-level language is valid for any computer, but the compiler that goes with it is specific to a particular type of CPU. Assembly language program is a series of statements, or lines, which are either Assembly language instructions or directives. Assembly language is suited to instrumentation and control applications such as found in a production facility. It is also used to write device drivers for peripheral devices because necessary instructions are not readily available in high-level languages Assembly language instructions such as ADD and MOV. In assembly language, there are two types of instructions : assembler directives and executable instructions. Assembler directives provide the assembler with various types of information such as space requirements, or where to begin executing instructions. Executable instructions can be directly translated to machine code and include arithmetic and other operations. Directives such as DB (define byte), DW (define word), END, and ENDP. An Assembly language instruction consists of four fields: [label:] mnemonic [operands] [;comment] Brackets indicate that the field is optional. The label field allows the program to refer to a line of code by name. A label must end with a colon when it refers to an opcode generating instruction; the colon indicates to the assembler that this refers to code within this code segment. The comment field begins with a";". Comments may be at the end of a line or on a line by themselves. The assembler ignores comments, but they are indispensable to programmers. Comments are optional, but are highly recommended to make it easier for someone to read and understand the program The Assembly language mnemonic (instruction) and operand(s) fields together perform the real work of the program and accomplish the tasks for which the program was written. ADD AL,BL MOV AX,6764 marks the ;THE FORM OF AN ASSEMBLY LANGUAGE PROGRAM beginning ;NOTE: USING SIMPLIFIED SEGMENT DEFINITION of the stack.MODEL SMALL selects the size of the memory segment.STACK64 model (SMALL, MEDIUM,.DATA COMPACT, and LARGE) marks the DATA1 DB 52H beginning DATA2 DB 29H A procedure is a group of instructions of the data SUM DB ? designed to accomplish a specific segment.CODE function. MAIN PROC FAR ;this is the program entry point marks the MOV AX,@DATA ;load the data segment address beginning MOV DS,AX ;assign value to DS of the code MOV AL,DATA1 ;get the first operand segment MOV BL,DATA2 ;get the second operand ADD AL,BL ;add the operands MOV SUM,AL ;store the result in location SUM MOV AH,4CH ;set up to return to DOS INT 21H ENDP are grouped into segments in order to be recognized by the Assembly language statements assembler and consequently MAIN by the CPU. END MAIN ;this is the program exit point The stack segment defines storage for the stack, the data segment defines the data Figure 8-1. Simple Assembly Language Program that the program will use, and the code segment contains the Assembly language instructions. An interrupt is a signal or instruction that causes the current process to be temporarily stopped while a service routine is run. In microprocessor based systems, there are three ways to start a service routine for a peripheral device. These are: Polled I/O Interrupts Interrupt driven I/O Interrupts Software Interrupts Polled I/O – the CPU tests each device one at a time to check if it needs service. If it does, the service routine is invoked. Interrupt driven I/O – the peripheral device requests service by sending an interrupt request signal. The CPU acknowledges the interrupt, fetches the service routine, and returns to its program when the routine is completed. Software interrupts – a software interrupt is issued from software rather than external hardware. After the interrupt occurs, the steps are the same as with a hardware interrupt. All I/O data transfers pass through the CPU Direct memory access (DMA) is a data transfer technique in which data is transferred to or from a peripheral device and memory without involving the CPU. A DMA controller handles the transfer. The transfer is faster using this method. It is often necessary to communicate with various devices in systems. Often, the devices are connected together with a bus and access to the bus is controlled by a bus controller or bus arbitrator to a void conflicts. Port : a physical interface on a computer through which data are passed to or from a peripheral. Interrupt : a computer signal or instruction that causes the current process to be temporarily stopped while a service routine is run. Assembly language: a programming language that uses English like words and has a one-to-one correspondence to machine language تم بحمد هللا و توفيقه