Presentation is loading. Please wait.

Presentation is loading. Please wait.

In Class Program Write, assemble and test a program: –Use the DB directive to define the following list of numbers and name it array: 31h, 32h, 33h, 34h.

Similar presentations


Presentation on theme: "In Class Program Write, assemble and test a program: –Use the DB directive to define the following list of numbers and name it array: 31h, 32h, 33h, 34h."— Presentation transcript:

1 In Class Program Write, assemble and test a program: –Use the DB directive to define the following list of numbers and name it array: 31h, 32h, 33h, 34h –Write instructions to load each number into DL and display it on the console. (use Int 21h, function 4Ch to display the byte in DL on the console) Explain why the output is “1234”

2 Procedure Get templatetemplate Make necessary changes. Assemble and Link using make16 Run and debug using Codeview

3 Template for Assembler Programs (Spring, 2003) ;*********************************************** ; Program Name * ;*********************************************** title INCLUDE Irvine16.inc ;*********************************************** ; Data Segment * ;***********************************************.data ; put data here ;*********************************************** ; Code Segment * ;***********************************************.code main proc mov ax,@data mov ds,ax ;initialize DS register ; put code here mov ah,4Ch ;int 21h function 4c int 21h ;return to DOS main endp end main ;end of program

4 Defining Data.data List byte 31h, 32h, 33h, 34h

5 Writing to Standard Output Interrupt 21h (MS-DOS Services) –Function 2 Write character stored in DL to standard out (Appendix C-2, page 652 of Irvine 4 th Edition) We have to get the data from memory to register DL and then Mov ah,2; use the mov instruction to ; store the interrupt 21h ; function number in register AH Int 21h; use int instruction to process ; interrupt

6 Moving Data from Memory to DL MOV destination, source –The source operand is unchanged! –Both operands must be the same size –Both operands cannot be memory operands! –CS and IP cannot be destination operands –An immediate value cannot be moved to a segment register

7 MOV Instruction MOVreg, reg MOVmem, reg MOVreg, mem MOVmem, imm MOVreg, imm In real address mode –MOVr/m16, sreg –MOVsreg, r/m16

8 Moving Data from Memory to DL Mov dl, list; AL = 31h Mov dl, list + 1; AL = 32h Mov dl, list + 2; AL = 33h Mov dl, list + 3; AL = 34h

9 Using Direct-Offset Operands The data in list (31h, 32h, 33h, 34h) can be accessed using the label (list). Putting brackets around the source operand does not affect the outcome. They are not required by MASM. –List+1 == [List+1] Use List+2, List+4, etc… for WORD lists Use List+4, List+8, etc… for DWORD lists

10 Title Writing_1234_to_Screen (1234_2.ASM) INCLUDE irvine16.inc.data array db 31h,32h,33h,34h;use db to define each element as 1 byte.code mainproc movax,@data;copy the address of the data movds,ax;segment(@data) into the DS register movah,2;int 21 function 2 displays the character in DL movdl, array;copy 1st byte of array to dl int21h movdl, array+1;copy 2nd byte to dl - uses direct-offset to access list elements int 21h movdl, array+2;copy 3rd byte to dl int21h movdl, array+3;copy 4th byte to dl int21h movax, 4c00h;terminate program and return to DOS int21h mainendp endmain

11 Can INC instruction be used to access different elements of the list ? The INC instruction adds 1 to a single operand –INC reg/mem So can we use –INC array (example program)example program No! The only practical way to handle an array or list is to use a register as a pointer and change the register value to point to different elements of the list.

12 OFFSET Operator Returns the offset of a data label. In protected mode, an offset is always 32- bits long In real mode, an offset is always 16-bits long.

13 Change Code to … Mov bx, OFFSET list Mov dl, [bx] Int 21h Inc bx Mov dl, [bx] Int 21h Inc bx NOTE: Inc works because the data is bytes. Use: –Add bx,2 ;for word size data –Add bx,4 ;for Doubleword size data

14 LOOP Instruction LOOP provides a simple way to repeat a block of statements a specific number of times. CX (ECX) is automatically used as the counter LOOP destination is put at the end of a section of code to be repeated. First, CX is decremented, then CX is compared to zero. If CX is not equal to zero a jump is taken to the label identified by destination.

15 INCLUDE irvine16.inc.data array db 31h,32h,33h,34h;use db to define array COUNT = ($-array);The $ operator gives the value of the location counter..code mainproc movax, @data;copy the address of the data segment movds, ax;@data into the DS register movbx, offset array;the offset operator returns the 16-bit offset of a label movcx, COUNT;set up cx register as a counter register. movah, 02;use function 2 of int 21h - display char stored in dl on screen LP1:movdl, [bx];LP1 is a label int21h incbx loopLP1;decrement cx; if cx not =0,loop back to label LP1. movax, 4c00h int21h mainendp endmain


Download ppt "In Class Program Write, assemble and test a program: –Use the DB directive to define the following list of numbers and name it array: 31h, 32h, 33h, 34h."

Similar presentations


Ads by Google