COAL LAB 01 Lab Instructor: Ayeza Ghazanfar

9 Slides268.05 KB

COAL LAB 01 Lab Instructor: Ayeza Ghazanfar

LAB 01:BASIC ASSEMBLY LANGUAGE CONCEPTS Objectives: To install Irvine Library in visual studio Learn structure of program in assembly To learn basic operations used in assembly language

TITLE Template Structure of Program in Assembly Language (Template.asm); you can give your own title ; Program Description: ; The semi colon is used to start a COMMENT INCLUDE Irvine32.inc INCLUDE is a directive to Assembler Irvine32 is the Library name .data (you declare Variables here) .code Main PROC ; executable code begins here ; (write your code here) Exit ; return control to Operating System Main ENDP ; (insert additional procedure here we will do this is later labs) End main

All lines beginning with semicolon (;) are comments, are ignored by the assembler. TITLE: The TITLE directive mark the entire line as a comment, you can put anything here. Include Irvine32.inc: The include directive copies necessary definitions and setup information from a text file Irvine32.inc .data: The .data directive identifies the area of a program that contains variables. .code: The .code directive marks the beginning of the code segment, where all executable statements in a program located. Main PROC: The PROC directive identifies the beginning of a procedure. The name chosen for the procedure in our program is main. .Exit: The Exit statement calls a predefine MS-Window function that halts the program. .ENDP: The ENDP directive marks the end of the main procedure. END main: The END directive marks the last line of the program to be assembled.it identifies the name of program’s startup procedure.

Data Types available in Assembly Language

Data Registers

Sample Code Include Irvine32.inc.data Val1 DWORD 30000h Val2 DWORD 20000h Val3 DWORD 10000h .code main PROC mov eax,Val1 add eax,Val2 sub eax,Val3 call DumpRegs Exit main ENDP END main

mov: mov instruction copies data from source to destination. In above instruction value of Val1 copies to eax. Here is a list of general variant of mov mov reg,reg mov mem,reg mov reg,mem mov mem,imm mov reg,imm mov is very flexible in its use of operands, if the following rules are observed: Both operands must be the same size. Both operands cannot be memory operands. CS, EIP, and IP cannot be destination operands. An immediate value cannot be moved to a segment register.

call DumpRegs: The call DumpRegs procedure displays the EAX, EBX, ECX, EDX, ESI, EDI, ESP, EIP, EFL register in hexadecimal. call ReadInt: The ReadInt procedure reads a 32-bit signed integer from standard input and store value in eax register. call WriteInt: The writeInt procedure writes a 32-bit signed integer to standard output in decimal format. Before calling it, place the integer in eax. Defining String To create String data definition, enclose a sequence of character in quotation marks. The most common type of string ends with null byte, a byte containing the value 0. msg1 byte “hello world”, 0 A string can be spread across multiple lines without the necessity of supplying a label for each Line msg1 byte “An assembly language is a low-level programming language”,0dh,0ah Byte “Assembly language uses a mnemonic”,0dh,0ah Byte “ Many assemblers offer additional mechanisms”,0 0dh,0ah: are called either CR/LF or end-of-line character.

Back to top button