Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 46 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
46
Dung lượng
1,5 MB
Nội dung
• • – !"#$ – !"%"" """#$"" &"'"""( – !" $&instrucon set( ")*+, - )* .$/ $ )* $ 0 1 • • • • • ! ! • 2 • !" #$% • & • & "% &''()*+,-. • " %. • .. ./ , " + 3#4 +3 5#4 + 6 5 • (!&##- • 01##"2% • &3!01## • 4! 01## • 5 • "% • 5&''&606 • &'' • &6 • 06 • &67&6806 • 4 ! 7 5 • 988&7"08%:$## • 9 89 :#$/;<5 8=) :#$/>> 8?@ :#$/;$ , • ; • 9 • ,: (! &606 <06&6 ,/ label==== : A BC;" @ [...]... a constant in C programming or using the #define ) factor EQU 12 mov CX, factor 31 Assembly Program • Assembly language should be more effective and it will take up less memory space and run faster • In real-time application, the use of assembly program is required because program that is written in a high-level language probably could not respond quickly enough • You can also put assembly codes into... program in order to reduce the execution time!!!! 32 Assembly language programming • The syntax for different microprocessor may be different but the concept is the same so once you learn the assembly programming for one microprocessor, you can easily program other kinds of system • For example, programming the 8051 series is very similar to the 8086 33 Addressing Modes • Function of the addressing...Software model • In 8086, memory is divided into segments • Only 4 64K-byte segments are active and these are: code, stack, data, and extra • When you write your assembly language program for an 8086, theoretically you should define the different segments!!! • To access the active segments, it is via the segment register: CS (code), SS (stack), DS (data), ES (extra) • So when writing assembly language program,... DL to AH HLT ; Halt end of program data db 45 ; define a variable called data op1 db 6 ; define a variable called op1 27 Assembler for 8086 Emu8086 (http:// www.emu8086.com) – there is a trial version but it does not support all the features such as interrupt The emu8086 consists of a tutorial and the reference for a complete instruction set Keil – www.keil.com 28 Defining data in a program Data is... or even 128bit data • In 8086, only integer operations are supported!!! 18 A sample program code startup mov mov mov mov mov mov ; indicate start of code segment ; indicate start of program AX, 0 BX, 0000H CX, 0 SI, AX DI, AX BP, AX END ; end of file The flow of the program is usually top-down and instructions are executed one by one!!! 19 Assembly programming In general, an assembly program must include... well as the end of a segment Just like using main(){} in C++ Programming Example DSEG segment ‘data’ ; define the start of a data segment DSEG ENDS ; defines the end of a data segment Segment is the keyword DSEG is the name of the segment Similarly key words are used to define the beginning of a program, as well as the end 20 Assembly language programming Example CSEG segment ‘code’ START PROC FAR ; define... x[10], y, *z; Then to access different elements, you can do Z=x; *(x+2); x[0] = y How this can be done using assembly language programming? This is via different addressing modes!!!! 35 Register addressing mode • The operand to be accessed is specified as residing in an internal register of the 8086 • Eg MOV AX, BX • Move (MOV) contents of BX (the source operand), to AX (the destination operand) • Both... memory location • Therefore, one form of operation that you will use very frequent is the store (move) operation!!! • And using registers!!!!! 12 Example • In C++ A = B+C ; A, B, C are variables • In assembly language A,B, C representing memory locations so you cannot do A = B+C – MOV AL, B ; move value of B into AL register – ADD, AL, C ; do the add AL = AL +C – MOV A, AL ; put the result to A 13 Data... directly into the segment register!!! END – ends the entire program and appears as the last statement Usually the name of the first or only PROC designated as FAR is put after END 25 Syntax of a simple assembly language program • If you are doing something simple then you do not need to define the segment • Everything will be stored in the code segment 26 start: mov DL, 0H mov CL, op1 mov AL, data ; move... (stack), DS (data), ES (extra) • So when writing assembly language program, you must make use of the proper segment register or index register when you want to access the memory 11 Registers • In assembly programming, you cannot operate on two memory locations in the same instruction • So you usually need to store (move) value of one location into a register and then perform your operation • After . G""# "+Just like using main(){} in C++ Programming 5 >B5IJ"K:"4" >B5I5!>B:"4"" B">B5I B"""4