assembly lecture4

30
Lecture 4 Chapter 6 –Symbolic Instruction and Addressing 1

Upload: nurul-badriah-anwar-ali

Post on 18-Aug-2015

254 views

Category:

Documents


0 download

DESCRIPTION

Computer is an interesting language

TRANSCRIPT

Lecture 4Chapter 6 Symbolic Instruction and Addressing1Chapter OutlineData Transfer Instructionasic Arithmetic InstructionThe I!T Instruction2"egisters Information inside the microprocessor is stored in registers. The registers are classified according to the functions they perform In general there are fourteen 16-bit registers: Data registers: There are four general data registers. They hold data for an operation. Address registers: They are diided into segment! pointer! and inde" registers. They hold the address of an instruction or data. #tatus register: It is called the $%A register. It 'eeps the current status of the processor.("egistersA) A%*) *%+) +%D) D%A,*,+,D,+#D###-##IDI#.*.I.Data /egisters#egment /egisters.ointer and Inde" /egisters$%A /egister0Data "egisters# A$% $% C$% D$ These four registers! in addition to being general-purpose registers! also perform special functions.The high and lo1 bytes of these registers can be accessed separately. -". The high byte of A, is called A)! and the lo1 byte is called A%. This arrangement gies us more registers to use 1hen dealing 1ith byte-si2e data.3Data "egisters# A$% $% C$% D$ A, &Accumulator "egister' is the preferred register to use in arithmetic! logic! and data transfer instructions *, &ase "egister' also seres as an address register. C$ &Count "egister' .rogram loop constructions are facilitated by the use of +,! 1hich seres as a loop counter.D, &Data "egister' is used in multiplication and diision.6Address "egisters ( Segment "egisters CS% DS% SS% )S Address registers store addresses of instructions and data in memory. These alues are used by the processor to access memory locations. In the 4546 processor 616-bit processor7: 8emory is a collection of bytes! each memory byte has an address! starting 1ith 5. The processor assigns a 25-bit physical address to its memory locations thus it is possible to address 2 9 1!504!3:6 bytes 6one megabyte7 of memory. The bytes in memory hae addresses 55555h to $$$$$h.25:Address "egisters ( Segment "egisters CS% DS% SS% )S To 'eep trac' of the arious program segments! the 4546 is e;uipped 1ith four segments registers to hold segment numbers: +# 6+ode #egment7: contains the code segment number. D# 6Data segment7: contains the data segment number. ## 6#tac' #egment7: contains the stac' segment number. -# 6-"tra #egment7: is used if a program needs to access a second data segment.4Address "egisters ( *ointer and Inde+ "egisters# S*% *% SI% DI #. 6#tac' .ointer7 register is used in connli'e other registers! the I. cannot be directly manipulated by an instruction 6i.e. The instruction cannot contain I. as its operand7.1511Data Transfer Instruction8?@8?@#,-8?@A,,+)&%-A,O- Instruction The 8?@ 6moe7 instruction is used to: Transfer data bet1een /egisters. Transfer data bet1een registers and memory locations. 8oe a number directly into a register or memory location. #ynta":8?@ destination! source -"ample:8?@ A,! B?/D18?@ A,! *,8?@ A,! CAC*efore After 55565554A,A, 55545554B?/D1B?/D1Dote: any register can be used e"cept +# E I.12Legal Combinations of operands for ,O- Destination Operand .eneral Segment ,emory Source operand register registerlocationConstant .eneral registeryes yesyes noSegment registeryes noyesno,emory location yes yesno noConstant yes noyes no Illegal: 8?@ B?/D1! B?/D2 %egal:8?@ A,! B?/D2 8?@ B?/D1! A, Illegal: 8?@ D#! +# %egal:8?@ A,! +#8?@ D#! A,1(Type Agreement of Operands The operands of any t1o-operand instruction must be of the same type 6i.e. *oth bytes or 1ords7. Illegal: 8?@ A,! *FT-1 )o1eer! the assembler 1ill accept both of the follo1ing: 8?@ A)! CAC moes 01) into A) 8?@ A,! CAC moes 5501) into A,10,O-)(and(/ill Instruction &,O-S$(,O-0$' The 8?@#, 6moe7 instruction is used to: 8oe a byte or 1ord source to a 1ord or double1ord destination.>se 1ith signed arithmetic alues #ynta":8?@#, destination! source -"ample:8?@#,+,!15115555*. +,9 11111111 15115555

13,O-)(and(/ill Instruction &,O-S$(,O-0$' The 8?@A, 6moe7 instruction is used to: 8oe a byte or 1ord source to a 1ord or double1ord destination.>se 1ith unsigned arithmetic alues #ynta":8?@A, destination! source -"ample:8?@A,+,!15115555*. +,9 55555555 15115555

16$C1. Instruction The ,+)& 6e"change7 operation is used to e"change the contents of: T1o registers. A register and a memory location. #ynta":,+)& destination! source -"ample:,+)& A)! *%,+)& A,!B?/D1 *efore AfterA) A% A) A%*)*% *)*% 1A 55 53 55 55 53 55 1A1:Legal Combinations of operands for $C1.Destination Operand .eneral ,emory Source Operand registerlocation.eneral registeryes yes,emory location yes no14Data Definition G *asic Instructions 1:L)A Instruction %-A 6%oad -ffectie Address7 puts a copy of the source offset address into the destination. #ynta": %-A destination! source Bhere destination is a general register and source is a memory location -"ample: 8#& D* 01)! 02)! 0() %-A D,! 8#& puts the offset address of the ariable 8#& into D,.1=25asic Arithmetic InstructionADD#>*ID+D-+ADD and S2 Instructions The ADD 6add7 and #>* 6subtract7 instructions are used to: AddHsubtract the contents of: T1o registers. A register and a memory location. AddHsubtract a number toHfrom a register or memory location. #ynta": ADD destination! source #>* destination! source -"amples: ADD B?/D1! A, #>* A,! D,*eforeAfter 51*+ 51*+A,A, 532( 56D$ B?/D1 B?/D1*eforeAfter 5555 $$$$A,A, 5551 5551D, D,21Legal Combinations of operands for ADD 3 S2 Illegal: ADD *FT-1! *FT-2 %egal:8?@ A%! *FT-2 ADD *FT-1! A%Destination Operand .eneral ,emory Source Operand registerlocation.eneral registeryes yes,emory location yes noConstant yes yes22I!C and D)C Instructions ID+ 6increment7 is used to add 1 to the contents of a register or memory location. D-+ 6decrement7 is used to subtract 1 from a register or memory location. #ynta": ID+ destination D-+ destination -"amples: ID+ B?/D1 D-+ *FT-1*eforeAfter B?/D1 B?/D1 5552555(*eforeAfter*FT-1 *FT-1 $$$-$$$D2(I!T Instruction To ino'e a D?# or *I?# routine! the IDT 6interrupt7 instruction is used. $ormat: IDT interruptInumber 1here interruptInumber is a number that specifies a routine.I!T 45h IDT 21h may be used to ino'e a large number of D?# functions. A particular function is re;uested by placing a function number inthe A) register and ino'ing IDT 21h. #ome of the functions are: IDT21h functions e"pect input alues to be in certain registers and return output alues in other registers./unction number "outine1 single-'ey input2 single-character output= character string outputI!T 45h To ino'e the routine! the follo1ing instructions should be e"ecuted: 8?@ A)!1 J input 'ey function IDT 21) J A#+II code in A%/unction 5# Single(6ey InputInput:A) 9 1?utput: A% 9 A#+II code if character 'ey is pressed9 5 if non-character 'ey is pressedI!T 45h To ino'e the routine! the follo1ing instructions should be e"ecuted: 8?@ A)! 2 J display character function 8?@ D%! CKC J character is CKC 6or any other character7 IDT 21) J display character/unction 4# Display a character or e+ecute a control functionInput:A) 9 2D% 9 A#+II code of the character?utput A% 9 A#+II code of the characterI!T 45h $unction 2 may be used to perform control functions. If D% contains the A#+II code of a control character! IDT 21h causes the control function to be performed. The principal control characters are :ASCII code &1e+' Symbol /unction5:) *-% beep 6sounds a tone754) *# bac'space5=) )T tab5A) %$ line feed 6ne1 line75D) +/ carriage return 6start of current line7I!T 45h To ino'e the routine! the follo1ing instructions should be e"ecuted: 8?@ A,! LDATA 8?@ D#! A, 8?@ A)! = J display string function %-AD,! 8#& J get message 6%oad -ffectie Address7 IDT 21) J display string/unction 7# Display a stringInput:A) 9 =D, 9 offset address of string.The string must end 1ith a CMC characterA program containing a data segment should begins 1ith these t1o instructionsI!T 45h To ino'e the routine! the follo1ing instructions should be e"ecuted: 8?@ A)! 0+) J D?# e"it function IDT21) J e"it to D?#/unction 4C1# "eturning control to DOSInput:A) 9 0+)