Anda di halaman 1dari 3

Laboratory 2: Use of the .

EXE File

Type in the following programme using EMU8086 and include your Name, Class, Group, Year and Date. Save this programme as file: lab_2.asm. ; ; ; ; ; TITLE NAME DATE CLASS GROUP

Purpose of Lab Introduction to the format of the EXE file. REQUIREMENTS: You are required to type in the programme below using EMU8086 Emulator. SPECIFICATION:
1. Open a new .EXE template in the EMU8086 emulator. 2. Copy the Lab 2 programme below into the relevant segments of the 3. 4. 5. 6.

EMU8086 editor. Assemble and Emulate the programme using the Emulate option from the menubar. Run the programme using the Single Step option from the menubar. Examine the contents of the AX register and memory variables locations for word1, word2 and result. Change the variables for word1 and word2 and repeat steps 1 to 5.

DESIGN: You are expected to try and understand the flow of the programme.

IMPLEMENTATION:

The 8086 processor uses segmentation. It views a programme as being divided into segments. Namely code, data and stack segments. Hence, when you write an 8086 assembly language programme you must define these segments with special assembler directives: SEGMENT to begin a segment and ENDS to end a segment. Also we normally don't refer to specific memory addresses. Instead we use symbolic addresses and special directives to associate them with 8-bit.16-bit or 32-bit locations: DB DW and DD. We must tell the assembler what segment registers to use with what segments. To do this we use the ASSUME directive. We can label any instruction by preceding the instruction with the label we wish to use followed by a colon. The colon tells the assembler that the word preceding it was a label not an instruction. Labels are useful when we want to jump to a specific instruction during the execution of a programme loop. The difference between the .EXE and .COM is that .EXE can have different segments for data, code and stack but the .COM file always loads in the lowest available segment and 100h from the start of the segment. This means all code, data and stack must fit in one 64K segment. Hence, programming using the .COM needs more knowledge on the part of the programmers in the sense that they do not over write other data in the same segment.

Lab 2 Programme:
;************************************************************* ; Simple Arithmetic ; This programme demonstrates some simple arithmetic instructions. data_seg segment word1 dw 1234H word2 dw 5678H result dw ? data_seg ends stack_seg segment stack ; this segment is called data_seg ; Some type definitions for the variables we will declare: ; here we reserve two l6-bit locations which we can refer to using the symbolic addresses word and word2. . ; They are initialised to HEX 1234 and 5678. ; this is the end of the segment called data_seg ;a new segment called stack_seg. Because this is specially used ;for the stack we specify this by following the segment directive ;with the special stack directive. ;the stack is 50 words long. block is the symbolic address of the ;first of the fifty locations. The other addresses are block+1 up ;to block+49. stack_seg ends code_seg segment assume cs:code_seg, ds:data_seg,ss:stack_seg main: mov ax,data_seg ;programmer must initialize mov ds, ax ; DS and ES register ;for EXE programmes mov ax,word1 add ax,word2 mov result,ax code_seg ends end main end ;*************************************************************

block dw 50 dup(?)