






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Course Instructor: Dated: Lab Engineer 1: Semester: Lab Engineer 2: Session:
Name Roll number Report (out of 25) Scaled to 10 Viva (out of 5) Total (out of 15) Muhammad Bilal Hassan bsee Checked on: ____________________________ Signature: ____________________________
EE243L: Microcontrollers and Interfacing Lab
This lab introduces students to memory access in assembly language. Data definition in memory and transfer to CPU registers is studied. Students also learn how to initialize arrays in memory and manipulate array data. A brief introduction of the addressing modes in assembly language is also offered.
This lab will enable students to achieve the following: Use memory by defining variables and arrays in memory Learn how to perform arithmetic and logical operations on data in memory Find size and length of arrays and manipulate data stored in arrays Learn about the different addressing modes in x86 assembly language
2.1.1 Data types and data definition statement [variable-name] define-directive initial-value The following is an example of a data definition statement: count DWORD 12345 Table 2. 1 : Intrinsic data types and their sizes in memory Type Usage BYTE 8-bit unsigned integer. B stands for byte SBYTE 8-bit signed integer. S stands for signed WORD 16-bit unsigned integer SWORD 16-bit signed integer DWORD 32-bit unsigned integer. D stands for double SDWORD 32-bit signed integer. SD stands for signed double TBYTE 80-bit (10 byte) integer REAL4 32-bit (4 byte) IEEE floating-point number REAL8 64-bit (8 byte) IEEE double-precision floating-point number REAL10 80-bit (10 byte) IEEE extended-precision floating-point number 2.1.2 Defining memory locations The following lines of code illustrate how to assign labels to memory: DATA SEGMENT MEMBDS DB?
EE243L: Microcontrollers and Interfacing Lab byte1 BYTE 10, 20, 30 array3 DWORD 1, 2, 3, 4 digitStr BYTE "12345678", 0 LENGTHOF byte1; returns 3 LENGTHOF array3; returns 4 LENGTHOF digitStr; returns 9
The following table shows the different addressing modes of x86 microprocessor assembly language: Table 2. 2 : Addressing modes in x86 assembly language Addressing Mode Mnemonic Description Immediate MOV AX, 1000H Source of data is within instruction Register MOV DX, CX Source and destination of data are CPU registers Direct MOV AH, [MEMBDS] Memory address is supplied within the instruction Register indirect MOV AX, [SI] Memory address is supplied in an index or pointer register Indexed MOV AX, [SI + 6] Memory address is the sum of the index register plus a displacement within the instruction Based MOV AX, [BP + 2] Memory address is the sum of the BX or BP base registers plus a displacement within instruction Based and indexed MOV AX, [BX + SI] Memory address is the sum of an index register and a base register Based and indexed with displacement MOV AX, [BX + SI + 5]^ Memory address is the sum of an index register, a base register and a displacement within instruction 2.3.1 Indirect operands for memory access An indirect operand can be any 32-bit general-purpose register (EAX, EBX, ECX, EDX, ESI, EDI, EBP, and ESP) surrounded by brackets. The register is assumed to contain the address of some data. In the next example, ESI contains the offset of byteVal. The MOV instruction uses the indirect operand as the source, the offset in ESI is dereferenced, and a byte is moved to AL: .data byteVal BYTE 10h .code mov esi, OFFSET byteVal mov al, [esi]; AL = 10h If the destination operand uses indirect addressing, a new value is placed in memory at the location pointed to by the register. In the following example, the contents of the BL register are copied to the memory location addressed by ESI. mov [esi], bl Indirect operands are ideal tools for stepping through arrays. In the following example, arrayB contains 3 bytes. As ESI is incremented, it points to each byte, in order: .data arrayB BYTE 10h, 20h, 30h .code mov esi, OFFSET arrayB mov al, [esi]; AL = 10h inc esi mov al, [esi]; AL = 20h inc esi mov al, [esi]; AL = 30h
Lab- 2
.data arrayB BYTE 10h, 20h, 30h .code main PROC mov AL, arrayB mov BL, [arrayB + 1] mov CL, [arrayB + 2] add AL, BL add AL, CL mov [arrayB + 3], AL INVOKE ExitProcess, main ENDP END main
------------------------------------------------------------------------------- ------- .data arrayD DWORD 10h, 20h, 30h .code main PROC mov EAX, arrayD mov EBX, [arrayD + 4] mov ECX, [arrayD + 8] add EAX, EBX add EAX, ECX mov [arrayD + 12], EAX INVOKE ExitProcess, main ENDP
Lab- 2
EE243L: Microcontrollers and Interfacing Lab
EE243L: Microcontrollers and Interfacing Lab Signature: ________________________ Signature: ________________________ Date: ____________________________ Date: ____________________________