TITLE: Library Calls and Procedures (LibCallProc1.asm) ;------------------------------------------------------------ ; Name: ; ; Filename: LibCallProc1.asm ; ; Project #: 3 ; ; Completed: February 16, 2003 ; ; Description: My third assembly program. Will demonstrate ; library calls and procedures using problems ; from Assembly Language For Intel-Based Computers, ; 4th Ed. by Kip R. Irvine. Problems are #1 on pg. ; 176, and #6,#7 and #8 on pg. 177. ; ; Reference: Assembly Language For Intel-Based Computers, ; 4th Ed. by Kip R. Irvine ;------------------------------------------------------------ INCLUDE Irvine32.inc .data strColor byte "Four",0dh,0ah randStr byte 10 DUP(0),0 msgIntro byte "This is My Name's third assembly program and I will",0dh,0ah byte "demonstrate library calls and procedures using questions",0dh,0ah byte "1 on page 176, and questions 6,7 and 8 on page 177.",0dh,0ah,0 msg1 byte "-------------------------------------",0dh,0ah byte "Demonstrating question 1 on page 176.",0dh,0ah byte "-------------------------------------",0dh,0ah,0 msg2 byte "-------------------------------------",0dh,0ah byte "Demonstrating question 6 on page 177.",0dh,0ah byte "-------------------------------------",0dh,0ah,0 msg3 byte "-------------------------------------",0dh,0ah byte "Demonstrating question 7 on page 177.",0dh,0ah byte "-------------------------------------",0dh,0ah,0 msg4 byte "-------------------------------------",0dh,0ah byte "Demonstrating question 8 on page 177.",0dh,0ah byte "-------------------------------------",0dh,0ah,0 .code main PROC ;///////Intro Message///////////////////////////////// mov edx,OFFSET msgIntro ;intro message into edx call WriteString ;display msgIntro call Crlf ;endl call WaitMsg ;pause message call Clrscr ;clear screen call colorString ;print string different colors call ranString ;print random CAPITAL letter stings call gotoxyRand ;print char on screen 100 random places call clrMatrix ;print char (all possible color schemes) exit main ENDP ;///////Question 1 on page 176///////////////////////// ;----------------------------------------------------------- colorString PROC Uses ESI EDX ECX EAX ; ;Prints out a string in four different colors starting at ;color 10=lightgreen. ;Receives: ESI points to the array ; EDX message display ; ECX = size of array ; EAX = stack to store characters ;Returns: String in different colors ;----------------------------------------------------------- mov edx,OFFSET msg1 ;explain message call WriteString ;display msg1 mov esi,0 ;set start index to 0 mov al,10 ;start first color at 10=lightgreen mov ecx,SIZEOF strColor;loop counter L1:;//Loop call SetTextColor ;change text color push eax ;color scheme into eax mov al,strColor[esi] ;move character to al inc esi call WriteChar ;write character in al pop eax inc al ;go to next color loop L1 ;do loop call Crlf ;endl mov eax,7 ;normal colors call SetTextColor ;change text color call WaitMsg ;pause message call Clrscr ;clear screen ret ;return colorString ENDP ;///////Question 6 on page 177///////////////////////// ;----------------------------------------------------------- ranString PROC Uses ESI EDX ECX EAX ; ;Prints out 20 random strings with 10 CAPITAL letters in each ;string. ;Receives: ESI array ; EDX message display ; ECX = count of loops ; EAX = characters ;Returns: 20 Random strings 10 CAPITAL letters long ;----------------------------------------------------------- mov edx,OFFSET msg2 ;explain message call WriteString ;display msg2 mov ecx,20 ;outer loop count(Strings=20) L1:;//Outer Loop(Generate String) push ecx ;push outer loop count into ecx mov ecx,10 ;loop counter(Letters=10) mov esi,OFFSET randStr;string index L2:;//Inner Loop(Generate Random Char) mov eax,26 ;random int [0-25] call RandomRange ;call RandomRange from library add eax,'A' ;{'A'..'Z'} mov [esi],al ;move character into array inc esi ;go to next character loop L2 mov edx,OFFSET randStr ;random string call WriteString ;display randStr call Crlf ;endl pop ecx ;restore outer loop count loop L1 ;run outer loop again call WaitMsg ;pause message call Clrscr ;clear screen ret ;return ranString ENDP ;///////Question 7 on page 177///////////////////////// ;----------------------------------------------------------- gotoxyRand PROC Uses EDX ECX EAX ; ;Prints out a character in 100 different random location on ;the screen. ;Receives: EDX message display ; ECX = counter loop amount ; EAX = store delay values and use for random num ;Returns: Character in 100 random screen locations ;----------------------------------------------------------- mov edx,OFFSET msg3 ;explain message call WriteString ;display msg3 call WaitMsg ;pause message call Clrscr ;clear screen mov ecx,100 ;loop counter(100 Screen Locations) mov dh,2 ;start row 2 mov dl,0 ;start column 0 L1:;//Loop(Place Char In Random Screen Location) call Gotoxy ;go to set screen location mov al,'*' ;mov * to al for display call WriteChar ;display * at set screen location mov eax,150 ;set pause time to 150 ms call Delay ;pause for 150 ms mov eax,25 ;set eax to 25 call RandomRange ;call random number(n-1) or eax-1 mov dh,al ;mov al value to dh to change row mov eax,80 ;set eax to 80 call RandomRange ;call random number(n-1) or eax-1 mov dl,al ;mov al value to dl to change column loop L1 ;do loop mov dh,24 ;set cursor to row 24 mov dl,0 ;set cursor to column 0 call Gotoxy ;go to set screen location call Crlf ;endl call WaitMsg ;pause message call Clrscr ;clear screen ret ;return gotoxyRand ENDP ;///////Question 8 on page 177///////////////////////// ;----------------------------------------------------------- clrMatrix PROC Uses ECX EAX EDX ; ;Prints out a character in all posible color scheme ;(16x16 = 256). ;Receives: EDX message display ; ECX = loop counter for row and columns ; EAX = stack to store color schemes ;Returns: Character printed in differerent 16x16 color schemes ;----------------------------------------------------------- mov edx,OFFSET msg4 ;explain message call WriteString ;display msg4 mov eax,0 ;colors start at 0=black mov ecx,16 ;loop counter(16 rows) L1:;//Outer Loop push ecx ;push colors into ecx stack mov ecx,16 ;loop counter(16 columns) L2:;//Inner Loop call SetTextColor ;call color scheme push eax ;push colors into eax stack mov al,'*' ;mov char into al call WriteChar ;display char in al pop eax ;pop out text color inc al ;move up to next text color loop L2 ;do loop call Crlf ;endl pop ecx ;pop out next background color loop L1 ;do loop mov eax,7 ;normal colors call SetTextColor ;call color scheme call WaitMsg ;pause message call Clrscr ;clear screen ret ;return clrMatrix ENDP END main