DOSSEG ; A Assembler program that does something ; Author: Curt Hill ; Purpose: Demonstrate string instructions ;Data section .model large .stack 100h .586 .data ; Line to make it easy to count blanks numline db 13,10,'123456789012345678901234567890123456789012345678901234567890' db 13,10,'$' greeting db 'This program demonstrates string instructions',13,10,'$' farewell db 'This program is complete. ',13,10,'$' tabmsg db 'Display a table:',13,10,'$' summsg db 'Sum of table is ' sumslot db ' ',13,10,'$' c_str db 'Null terminated string. ->',0,'<- (After the null)',13,10,'$' lodsmsg db 'Use LODS/STOS to add two arrays',13,10,'$' lenline db 'Length used: ' blank db 64 dup (?),8 dup (' '),13,10,'$' buffer db 100 dup (' '),13,10,'$' dd 9999 tab1 dd -2,5,1509,-210,10 dd -9999 tab2 dd -4,9,1,-100,225492 resTab dd 5 dup (0) .code ; Here is the code start: mov ax,@data ; Address the data mov ds,ax ; mov es,ds -- Nope this won't work mov es,ax ; but this does ; Greeting mov ah,9 lea dx,greeting int 21h ; ; ; Display a table demonstrating LODS lea ax,tab1 lea bx,blank call displaytab mov ah,9 lea dx,tabmsg int 21H lea dx,blank int 21H ; Show the sum of the table lea eax,tab1 mov ecx,5 call sumtable lea ebx,sumslot call int_to_str mov ah,9 lea dx,summsg int 21h lea ax,tab2 lea bx,blank call displaytab mov ah,9 lea dx,blank int 21H ; Add two tables lea ax,tab1 lea bx,tab2 lea cx,restab call addtabp ; Display the result lea ax,restab lea bx,blank call displaytab mov ah,9 lea dx,blank int 21H ; ; Find a null ; lea dx,numline ; Print number line mov ah,9 int 21h lea dx,c_str ; Print the line int 21h lea ax,blank ; Clear the line mov cx,64 call clearp xor eax,eax ; print header lines lea ax,c_str mov cx,200 call findnullp ; find the null lea bx,blank call int_to_str mov ah,9 lea dx,lenline int 21h ; ; Skip blanks ; lea bx,blank ; Clear the line mov cx,64 call clearp mov blank+41,'X' ; Put a nonblank in lea dx,numline ; Print number line mov ah,9 int 21h lea dx,blank ; Print the line int 21h lea ax,blank mov cx,64 call skipblnkp lea bx,blank call int_to_str lea dx,lenline mov ah,9 int 21h ; ; All done ; mov ah,9 lea dx,farewell int 21h mov ax,4c00h ; Leave the program int 21h ; ; Subroutines ; ; ; sumtable - find the sum of a table ; ; eax - address of table, return value ; cx - maximum count sumtable proc near push si push cx push ebx xor ebx,ebx mov esi,eax summer: lodsd add ebx,eax loop summer ; Restore registers mov eax,ebx pop ebx pop cx pop si ret sumtable endp ; ; findnullp - find null character in a string ; ; ax - address of first table, return length ; cx - maximum count findnullp proc near ; push eax push bx push cx push di mov di,ax mov bx,ax xor al,al repnz scasb mov ax,di sub ax,bx pop di pop cx pop bx ; pop eax ret findnullp endp ; ; skipblnkp - find first non-blank character in a string ; ; ax - address of first table, return length ; cx - maximum count skipblnkp proc near ; push eax push bx push cx push di mov di,ax mov bx,ax mov al,' ' repe scasb mov ax,di sub ax,bx pop di pop cx pop bx ; pop eax ret skipblnkp endp ; ; AddTab - add two tables ; ; ax - address of first table ; bx - address of second table ; cx - address of result table addtabp proc near push eax push bx push cx push edx push si push di mov di,cx mov cx,5 mov si,ax xor edx,edx ; registers in the loop: ; eax move destination location ; bx/si address of two tables ; cx - count ; edx - temp location for tab1 entry addloop1: lodsd ; move tab1 to eax xchg bx,si mov edx,eax lodsd add eax,edx stosd loop addloop1 pop di pop si pop edx pop cx pop bx pop eax ret addtabp endp ; ; Make a string representation of a table of length 5 ; ; AX contains address of table ; BX contains address of line displaytab proc near push eax push bx push cx push si mov cx,64 call clearp mov si,ax mov cx,5 dtloop: lodsd ; load into eax call int_to_str ; convert to string inc bx ; allow one blank between loop dtloop pop si pop cx pop bx pop eax ret displaytab endp ; ; Clear an area with blanks ; ; BX contains line ; CX contains count clearp proc near push ax push bx push cx push di mov di,bx mov al,' ' rep stosb pop di pop cx pop bx pop ax ret clearp endp ; clearp ; ; ; include int2str.asm ; Last line of assembly is end end