The first three parts are mandatory, while the last one is optional. Index or pointer registers: These registers are used to specify the address of memory locations by programmer in order to access operands from the memory locations in program segments. They are also referred to as logical address. It keeps the address of next instruction in the memory. The lower address of the segment is h and the higher address is FFFFh.
Segment registers: Stores base address number of the program parts. Size is 16bit. DS data segment register - for data , ES extra data segment register - for extra data, SS stack segment register - for stack, CS code segment register - for code. These registers are loaded with appropriate values by operating system during loading of program parts in the memory.
Mechanism of loading program parts in the memory: The physical memory for is 20bits. The operating system loads the various parts of the program at memory locations whose physical address has bits at positions a3, a2, a1, a0, - least significant nibble is b.
This address is also known as the paragraph boundary. For example: XXXX0h This address is divided by 16d or 10h to get the base address number which is loaded into the segment registers. Here the base address number will be XXXXh. Flag : It is the set of individual flip flops to show the conditions resulting out of operations in ALU of processor. Used to take decision. Programming model: The set of registers of the processor which are accessible to a programmer writing program in low level language.
The above mentioned registers form the programming model of microprocessor. Data processing is done in execution unit - EU. The address of memory location is formed in bus interface unit - BIU. Assembly operations: Can work upon maximum two operands variables only. Logical segments of an assembly program a Data segment — contains directives to reserve and initialize data variables b Stack segment — contains directives to reserve and initialize memory locations to keep return addresses and temporary variables c Code segment — contains codes to carry out data processing d Extra data segment - contains directives to reserve and initialize data variables, if the data segment is full.
This segment is optional 2. The starting memory location is given aa DB 05h some name, used for reference. SEG : load a register with segment base number. Related Papers. Assembly Language - 3. By Naimul Ferdous.
Assembly Lecture Assembly Language Full Lecture. Assembly Language - 4. Download pdf. Despite the name of a register, it's the programmer who determines the usage for each general purpose register. The main purpose of a register is to keep a number variable. The size of the above registers is 16 bit, it's something like: b in binary form , or in decimal human form. Therefore, when you modify any of the 8 bit registers 16 bit register is also updated, and vice-versa. The same is for other 3 registers, "H" is for high and "L" is for low part.
Because registers are located inside the CPU, they are much faster than memory. Accessing a memory location requires the use of a system bus, so it takes much longer. Accessing data in a register usually takes no time. Therefore, you should try to keep variables in the registers. Register sets are very small and most registers have special purposes which limit their use as variables, but they are still an excellent place to store temporary data of calculations.
Although it is possible to store any data in the segment registers, this is never a good idea. The segment registers have a very special purpose - pointing at accessible blocks of memory. Segment registers work together with general purpose register to access any memory value. This is good, since this way we can access much more memory than with a single register that is limited to 16 bit values.
Other general purpose registers cannot form an effective address! IP register always works together with CS segment register and it points to currently executing instruction.
Flags Register is modified automatically by CPU after mathematical operations, this allows to determine the type of the result, and to determine conditions to transfer control to other parts of the program.
Generally you cannot access these registers directly. Combining these registers inside [ ] symbols, we can get different memory locations. Displacement can be a immediate value or offset of a variable, or even both.
It's up to compiler to calculate a single immediate value. Displacement can be inside or outside of [ ] symbols, compiler generates the same machine code for both ways. Displacement is a signed value, so it can be both positive or negative. Generally the compiler takes care about difference between d8 and d16, and generates the required machine code.
By default DS segment register is used for all modes except those with BP register, for these SS segment register is used.
There is an easy way to remember all those possible combinations using this chart: Assembler Tutorial Prof. As you see BX and BP never go together. SI and DI also don't go together. When DS contains value h and SI contains the value h it can be also recorded as MicroAsm supports shorter prefixes as well: b. Select the above text using mouse, click before the text and drag it down until everything is selected. As you may guess, ";" is used for comments, anything after ";" symbol is ignored by compiler.
You should see something like that when program finishes: this is how it looks in emu microprosessor emulator. Actually the above program writes directly to video memory, so you may see that MOV is a very powerful instruction. For a programmer it is much easier to have some value be kept in a variable named "var1" then at the address 5AB, especially when you have 10 or more variables.
DW - stays for Define Word. It's possible to declare unnamed variables by not specifying the name this variable will have an address but no name. As you probably know from part 2 of this tutorial, MOV instruction is used to copy values from source to destination. Then open the executable in any disassembler emu or any other. Compiler is not case sensitive, so "VAR1" and "var1" refer to the same variable. It is assumed that low byte is stored at lower address, so 34h is located before 12h.
You can see that there are some other instructions after the RET instruction, this happens because disassembler has no idea about where the data starts, it just processes the values in memory and it understands them as valid instructions we will learn them later.
You should get the same disassembled code, and the same functionality! As you may guess, the compiler just converts the program source to the set of bytes, this set is called machine code, processor understands the machine code and executes it. ORG h is a compiler directive it says to compiler how to handle the source code. This directive is very important when you work with variables. It says to compiler that the executable file will be loaded at the offset of h bytes , so compiler should calculate the correct address for all variables when it replaces the variable names with their offsets.
Directives are never converted to any real machine code. Why executable file is loaded at offset of h? Operating system keeps some data about the program in the first bytes of the CS code segment , such as command line parameters and etc.
Though this is true for COM files only, EXE files are loaded at offset of , and generally use special segment for variables. Maybe we'll talk more about EXE files later. Here are some array definition examples: a DB 48h, 65h, 6Ch, 6Ch, 6Fh, 00h b DB 'Hello', 0 b is an exact copy of the a array, when compiler sees a string inside quotes it automatically converts it to set of bytes.
DW cannot be used to declare strings! The expansion of DUP operand should not be over characters! LEA is more powerful because it also allows you to get the address of an indexed variables. Getting the address of the variable can be very useful in some situations, for example when you need to pass parameters to a procedure. After definition of a constant its value cannot be changed. To view arrays you should click on a variable andset Elements property to array size.
In assembly language there are not strict data types, so any variable can be presented as an array. It is possible to enter numbers in any system, hexadecimal numbers should have "h" suffix, binary "b" suffix, octal "o" suffix, decimal numbers require no suffix.
String can be entered this way: 'hello world', 0 this string is zero terminated. Arrays may be entered this way: 1, 2, 3, 4, 5 the array can be array of bytes or words, it depends whether BYTE or WORD is selected for edited variable.
These functions make the programming much easier, instead of writing a code to print a character you can simply call the interrupt and it will do everything for you.
There are also interrupt functions that work with disk drive and other hardware. We call such functions software interrupts. Interrupts are also triggered by different hardware, these are called hardware interrupts. Currently we are interested in software interrupts only. To make a software interrupt there is an INT instruction, it has very simple syntax: INT value where value can be a number between 0 to or 0 to 0FFh , generally we will use hexadecimal numbers.
You may think that there are only functions, but that is not correct. Each interrupt may have sub-functions. To specify a sub-function AH register should be set before calling interrupt. In general AH register is used, but sometimes other registers maybe in use. Generally other registers are used to pass parameters and data to sub-function.
This functions displays a character on the screen, advancing the cursor and scrolling the screen as necessary. ORG h ; The sub-function that we are using ; does not modify the AH register on ; return, so we may set it only once. MOV AL, '! RET ; returns to operating system.
Run it! See list of basic interrupts for information about other interrupts. Compiler automatically searches for the file in the same folder where the source file is located, and if it cannot find the file there - it searches in Inc folder.
Currently you may not be able to fully understand the contents of the emu To use any of the functions in emu To use any of the above macros simply type its name somewhere in your code, and if required parameters, for example: include emu END ; directive to stop the compiler. Generally macros are relatively small parts of code, frequent use of a macro may make your executable too big procedures are better for size optimization. Procedure stops the input when 'Enter' is pressed.
0コメント