ASSEMBLY LANGUAGE Assembler and Compiler Pascal A Program

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 n Supply more control in controlling certain devices n Execute more compact and smaller execution module n 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 n 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] n Statement example: n – Pointer: Assemble Language Syntax [LABEL/NAME] OPERATION [OPERANd] [; COMMENT] n Statement example: n – Pointer:](http://slidetodoc.com/presentation_image_h2/871fa739524c1fd06001872ed6e6af48/image-6.jpg)
Assemble Language Syntax [LABEL/NAME] OPERATION [OPERANd] [; COMMENT] n Statement example: n – Pointer: MAIN PROC ; operation name – Instruction: MOV AX, O ; opepration, 2 operand n Can be seen that assemble language instruction is in a form of OPERATION CODE OPERAND

Name/Label Field n Used to name instruction, procedure name or variable name n Length from 1 -31 character n Able to contain character, number and special character like ? . @ _ $ %. n Empty space is not allowed and special character must be at the beginning of a name

Name/Label Field n Example of valid name – – – KAUNTER 1 @aksara JUMLAH_DIGIT $100 OK? . CUBA n Example of invalid name – DUA PERKATAAN (empty space) – 3 abc(first character is a number) – A 42. 05(“. ” is not the first character)

Operation Field For instruction, contains operation code (opcode) in mnemonics form (combination of unique characters) n Assembler will translate the symbolic operation code into machine language operation/opcode n Opcode example is MOV, ADD and SUB. n For directive, contains pseudo operation code (pseudo-op) n Will not be translated into machine code but only inform assembler to do something n

Operand Field For instruction, operand field specifies data that will be executed by operation n Can contain 0, 1 or 2 operand n For 2 operand, operand 1 is the destination operand (consist of register or memory location where result is stored) n Second operand is the source operand n

Comment Field n Increase program understandability n Start with ; sign n Can contain printed character including empty space n Example: • ; this is a comment

Program Data n Assemble translate all data representation into binary number form n In assembly language programming, data can be represented in binary, decimal, hexadecimal and character form

Number Written in bit n sequence followed n by “B” or “b” (optional) n Similar for hexa and decimal number n n Example: Valid representation – 11011 (Decimal) – 11011 B (Binary) – -2322 D (Decimal) Invalid representation – 1, 234 (contains non digit character) – 1 B 4 D (there is no B in decimal number)

Character n Must written in bracket ‘ ’ or “ ” n Will be translated by assembler into equivalen ASCII n Example: the usage of “A” is similar to 41 h (ASCII code for “A”)

Pseudo-op n Pseudo-op defination Pseudo-op DB Defined as Define byte DW DD Define word Define doubleword (2 words) Define quadword (4 words) DQ

Variable n Each variable contains data type and address which will be accumulated by program n 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: • DATA 1 DB OFFH, OFFH is written as • DATA 1 DB 4 DUP (OFFH)

ii. Word Variable n Statement for define is in a form of name DW first-value example: WRD DW -2

Array n One memory sequence whether in byte or word n Eg: for 3 -byte array definition B_ARRAY which give starting value of 10 h, 20 h and 30 h is written as • B_ARRAY DB 10 H, 20 H, 30 H

n Let say an assemble prepare offset address 0200 H into B_ARRAY, memory is as below Symbol B_ARRAY Address 200 H Content 10 H B_ARRAY 201 H 20 H B_ARRAY 202 H 30 H

n If array DW is used, let say assembler prepare offset address 0300 H for W_ARRAY: W_ARRAY DW 1000, 40, 523 Symbol Address Content W_ARRAY 0300 H 1000 D W_ARRAY 0302 H +2 W_ARRAY 0304 H +4 40 D 50 D

Character sequence ASCII code array can be seen as a character sequence n Eg: HURUF DB ‘ABC’ is equivalent to HURUF DB 41 H, 42 H, 43 H n The usage of small letter and capital letter is different n Eg : HURUF DB ‘ABC’ = HURUF DB 41 H, 42 H, 43 H HURUF DB ‘abc’ = HURUF DB 61 H, 62 H, 63 H n

Character and number combination is allowed n Eg: MSG DB ‘HELLO’, 0 AH, 0 DH, ’$’ is equivalent to MSG DB 48 H, 45 H, 4 CH, 4 FH, 0 AH, 0 DH, 24 H n

Constant n Symbolic name is given to the used constant n EQU (equates) instruction is used n Syntax : name EQU constant n Statement example LF n This EQU 0 AH statement accumulate LF name to 0 AH (ASCII code) for line feed.

n All 0 AH usage can be replaced with LF and give the same result n Example: – MOV and – MOV DL, 0 AH DL, LF

Symbol at the right of EQU can be character sequence n Example: PROMPT EQU “TAIP NAMA ANDA” n Statement MSG DB PROMPT give equivalent result as MSG DB “TAIP NAMA ANDA” n There is no memory space for EQU instruction n

Program structure n Code, data and stack is structured as program segments n Will be translated into memory segment by assembler
- Slides: 27