Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
~CSC159~ Lab1 Introduction What is Assembly Language ? Assembly Language is a machine-specific programming language with a one-to-one correspondence between its statements and the computer’s native machine language. There are many different types of assembly language, each specific to a processor or processor family. Instructions in assembly language are designed to match a computer’s machine instruction set and hardware architecture. What is an Assembler? An assembler is a program that converts source-code programs from assembly language into machine language.The most popular assemblers for the Intel family are MASM (Microsoft Assembler), TASM (Borland Turbo Assembler) and ASM86. *** MS-DOS Command (c:\) C:\> cd (change directory) C:\> dir (display directories and files) C:\> mkdir (make directory) C:\> copy (copy files) C:\> Why Learn assembly Language? You may want to learn more about the computer you work with and about the way computer languages generate machine code. Machine Language Machine Language is a language made up of numbers, which can be interpreted by a computer’s processor. A processor usually has a built-in interpreter called a microprogram that interprets and translates machine instructions into hardware signals. Eg: MOV AL, 5 An example of an Intel machine language instruction that moves 5 into the AL register: 1011000000000101 The first 8 bits are the operation code (opcode), which identifies it as the instruction that moves an 8-bit number to the AL register. The second 8 bits are the operand. The complete instruction moves the number 5 to a register called AL. Opcode – MOV, ADD, SUB, INC, etc. Operand can be : a register : a variable : a memory location : an immediate value : AX count [memory location] 10 1 ~CSC159~ Lab1 Registers Intel 16-bit Registers. Index General Purpose BP AH AL BH BL H CH CL DH DL SP SI DI Segment CS Status & Control Flags SS IP DS ES Registers are high-speed storage locations inside the CPU that can hold 8, 16, or 32 bits. There are 3 types of registers : 1) General-purpose/Data Register 2) Address Register 3) Status Register 1) General-purpose / Data Registers are used for arithmetic data movement. Each register can be addressed as either a 16-bit or 8-bit value. Eg: AX register is a 16-bit register; its upper 8 bits are called AH and its lower 8 bits are called AL. Bit 0 in AL corresponds to bit 0 in AX and bit 0 in AH corresponds to bit 8 in AX. Each general-purpose register has special attributes: i) AX (accumulator) - is a accumulator for arithmetic operations. ii) BX (base) - can hold the address of a procedure or variable. - can also perform arithmetic and data movement. 2 ~CSC159~ Lab1 iii) CX (counter) - act as a counter for repeating or looping instructions. These instructions automatically repeat and decrement CX. iv) DX (data) - has a special role in multiply and divide operations. 2) Address Registers Are used to store memory address. There are 3 types of address registers: i) Segment Register - contains four segment registers, used as base locations for program instructions, data and the stack. - The segment registers are as follows: a) CS (code segment) - holds the base location of all executable instructions (code) in a program. b) DS (data segment) - is the default base location for variables. The CPU calculates their locations using the segment value in DS. c) SS (stack segment) - contains the base location of the stack. d) ES (extra segment) - is an additional base location for memory variables. ii) Pointer Register a) IP (instruction pointer) - always contains the offset of the next instruction to be executed within the current code segment. b) BP (base pointer) - contains an assumed offset from the SS register. c) SP (stack pointer) - contains the offset of the top of the stack. iii) Index Register a) SI (source index) - this register takes its name from the string movement instructions, in which the source string is pointed to by the SI register. b) DI (destination index) - acts as the destination for string movement instructions. (*** ii) & iii) also known as special-purpose registers) 3) Status Registers Also called Flag Registers or Program Status Word (PSW). 3 ~CSC159~ Lab1 Flag registers reflect the outcomes of arithmetic and logical operations performed by the CPU. Flags Sym bols CF Set Symb ol CY Clear Symb ol NC Carry Overfl ow Sign OF OV NV SF NG PL Zero ZF ZR NZ Interru pt Parity IF EI DI PF PE PO Purpose - is set when the result of an unsigned arithmetic operation is too large to fit into the destination. - is set when the result of a signed arithmetic operation is too wide (too many bits) to fit into the destination. - is set when the result of an arithmetic or logical operation generates a negative result. - is set when the result of an arithmetic or logical operation generates a result of zero. - dictates whether or not system interrupts can occur. - reflects the number of 1 bits in the result of an operation. Odd number -> PF=0, Even number -> PF=1 Example program: .model small .stack 0100h .data .code main proc mov AH, 03h mov BH, AH main endp end main To assemble your program : C:\Users\User>cd\MASM611\BIN C:\MASM611\BIN>md ASM_files C:\MASM611\BIN>edit ASM_files\lab1.asm Write this code .model small .stack 0100h .data .code main proc mov AH, 03h mov BH, AH main endp end main 4 ~CSC159~ Lab1 C:\ASM_files>masm test.asm If no error, proceed with this command: C:\ASM_files>ml test.asm This command will create an exe file (test.exe), you can start debug the file: C:\ASM_files>debug test.exe Debug Commands Command A G Q R T U Description Starts assembling a program, placing each instruction in memory. Execute the remainder of the program. Quits Debug. Displays the CPU registers. Traces (Execute) one program instruction. Unassemble 5