280 likes | 584 Views
ASSEMBLY LANGUAGE. Assembler and Compiler. Pascal A Program. Compiler. Version A Assembly Language. Assembler. Versiion A Machine Code. Actual version that will be executed. Relation between high level language and low level language. Advantage of Assembly Language Programming.
E N D
Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Assembler Versiion A Machine Code Actual version that will be executed Relation between high level language and low level language
Advantage of Assembly Language Programming • Supply more control in controlling certain devices • Execute more compact and smaller execution module • Faster execution time
Assembly Language Program Execution Editor:Wite assembly language program Source code Assembler Object Code Library Linker Execution Code Execution
Assemble Language Syntax • There are two types of statement • Instruction: example MOV and ADD, which translated by assembler into machine code • Pointer : instruct assembler to execute specific work such as create procedure to allocate memory space for variable
Assemble Language Syntax • [LABEL/NAME] OPERATION [OPERANd] [;COMMENT] • Statement example: • Pointer: MAIN PROC ;operation name • Instruction: MOV AX,O ;opepration,2 operand • Can be seen that assemble language instruction is in a form of OPERATION CODE OPERAND
Name/Label Field • Used to name instruction, procedure name or variable name • Length from 1-31 character • Able to contain character,number and special character like ? . @ _ $ %. • Empty space is not allowed and special character must be at the beginning of a name
Example of valid name KAUNTER1 @aksara JUMLAH_DIGIT $100 OK? .CUBA Example of invalid name DUA PERKATAAN (empty space) 3abc(first character is a number) A42.05(“.” is not the first character) Name/Label Field
For instruction, contains operation code (opcode) in mnemonics form (combination of unique characters) Assembler will translate the symbolic operation code into machine language operation/opcode Opcode example is MOV, ADD and SUB. For directive, contains pseudo operation code (pseudo-op) Will not be translated into machine code but only inform assembler to do something Operation Field
Operand Field • For instruction, operand field specifies data that will be executed by operation • Can contain 0, 1 or 2 operand • For 2 operand, operand 1 is the destination operand (consist of register or memory location where result is stored) • Second operand is the source operand
Comment Field • Increase program understandability • Start with ; sign • Can contain printed character including empty space • Example: • ; this is a comment
Program Data • Assemble translate all data representation into binary number form • In assembly language programming, data can be represented in binary, decimal, hexadecimal and character form
Written in bit sequence followed by “B” or “b” (optional) Similar for hexa and decimal number Example: Valid representation 11011 (Decimal) 11011B (Binary) -2322D (Decimal) Invalid representation 1,234 (contains non digit character) 1B4D (there is no B in decimal number) Number
Character • Must written in bracket ‘ ’ or “ ” • Will be translated by assembler into equivalen ASCII • Example: the usage of “A” is similar to 41h (ASCII code for “A”)
Pseudo-op • Pseudo-op defination
Variable • Each variable contains data type and address which will be accumulated by program • Declared as • name DB first-value • name DW last-value
i. Byte Variable • Statement for declaration is in a form of name DB first-value • Eg: ALPHA DB 4 • One space with 1 byte size will be prepared with ALPHA and started with value 4 • DUP instruction (duplicate) – for copy all character following the given number without repeated writing • Eg: • DATA1 DB OFFH,OFFH,OFFH,OFFH is written as • DATA1 DB 4 DUP (OFFH)
ii. Word Variable • Statement for define is in a form of name DW first-value example: WRD DW -2
Array • One memory sequence whether in byte or word • Eg: for 3-byte array definition B_ARRAY which give starting value of 10h, 20h and 30h is written as • B_ARRAY DB 10H, 20H, 30H
Let say an assemble prepare offset address 0200H into B_ARRAY, memory is as below
If array DW is used, let say assembler prepare offset address 0300H for W_ARRAY: W_ARRAY DW 1000, 40, 50, 523
Character sequence • ASCII code array can be seen as a character sequence • Eg: HURUF DB ‘ABC’ is equivalent to HURUF DB 41H, 42H, 43H • The usage of small letter and capital letter is different • Eg : HURUF DB ‘ABC’ = HURUF DB 41H,42H,43H HURUF DB ‘abc’ = HURUF DB 61H,62H,63H
Character and number combination is allowed • Eg: MSG DB ‘HELLO’,0AH,0DH,’$’ is equivalent to MSG DB 48H,45H,4CH,4FH,0AH,0DH,24H
Constant • Symbolic name is given to the used constant • EQU (equates) instruction is used • Syntax : name EQU constant • Statement example LF EQU 0AH • This statement accumulate LF name to 0AH (ASCII code) for line feed.
All 0AH usage can be replaced with LF and give the same result • Example: • MOV DL, 0AH and • MOV DL, LF
Symbol at the right of EQU can be character sequence • Example: PROMPT EQU “TAIP NAMA ANDA” • Statement MSG DB PROMPT give equivalent result as MSG DB “TAIP NAMA ANDA” • There is no memory space for EQU instruction
Program structure • Code, data and stack is structured as program segments • Will be translated into memory segment by assembler