Programs are translated into Instruction Set Architecture Level - machine language or assembly language. It is easy to maintain when programs are short and well documented. The executable code runs very quickly.
Final Assignment for Assembly Language
TITLE Assignment8 (Assignment8_main.asm)
; This program inputs multiple characters from the user,
; stores them in the arrays, compares the two arrays,
; and displays the result.
; Author: Francis Nguyen
; Date Created: 12/3/2010
; Last Modification Date: 12/3/2010
; Uses Invoke to access Invokeal procedures
INCLUDE compare.inc
; modify Count to change the size of the array:
Count = 3
.data
equal BYTE "The two arrays are equal.",0
notEqual BYTE "The two arrays are not equal.",0
str1 BYTE "Please enter 3 characters for the first array: ",0
str2 BYTE "Please enter 3 characters for the second array: ",0
strA BYTE "Array A:",0
strB BYTE "Array B:",0
arrayA DWORD Count DUP(?)
arrayB DWORD Count DUP(?)
.code
main PROC
call Clrscr
INVOKE PromptA,
ADDR str1,
Count,
ADDR arrayA
INVOKE PromptB,
ADDR str2,
Count,
ADDR arrayB
call Crlf
INVOKE DisplayA,
ADDR strA,
Count,
ADDR arrayA
call Crlf
INVOKE DisplayB,
ADDR strB,
Count,
ADDR arrayB
call Crlf
INVOKE Compare,
Count,
ADDR arrayA,
ADDR arrayB,
ADDR equal,
ADDR notEqual
call Crlf
exit
main ENDP
END main
; Include file for the Assignment 8 Program (compare.inc)
INCLUDE Irvine32.inc
PromptA PROTO,
ptrPrompt:PTR BYTE, ; prompt string
arraySize:DWORD, ; size of the array
ptrArray:PTR DWORD ; points to the array
PromptB PROTO,
ptrPrompt:PTR BYTE, ; prompt string
arraySize:DWORD, ; size of the array
ptrArray:PTR DWORD ; points to the array
DisplayA PROTO,
ptrPrompt:PTR BYTE, ; prompt string
arraySize:DWORD, ; size of the array
ptrArray:PTR DWORD ; points to the array
DisplayB PROTO,
ptrPrompt:PTR BYTE, ; prompt string
arraySize:DWORD, ; size of the array
ptrArray:PTR DWORD ; points to the array
Compare PROTO,
arraySize:DWORD, ; size of the array
ptrArrayA:PTR DWORD, ; points to the array
ptrArrayB:PTR DWORD, ; points to the array
ptrPromptEqual:PTR BYTE, ; prompt string
ptrPromptNotEqual:PTR BYTE ; prompt string
TITLE PromptA (_promptA.asm)
; Author: Francis Nguyen
; Date Created: 12/3/2010
; Last Modification Date: 12/3/2010
INCLUDE compare.inc
.code
;-----------------------------------------------------
PromptA PROC,
ptrPrompt:PTR BYTE, ; prompt string
arraySize:DWORD, ; size of the array
ptrArray:PTR DWORD ; points to the array
; Prompts the user for an arrayA of characters and fills
; the array with the user's input.
; Receives:
; ptrPrompt:PTR BYTE ; prompt string
; arraySize:DWORD ; size of the array
; ptrArray:PTR DWORD ; pointer to array
; Returns: nothing
;-----------------------------------------------------
mov ecx,arraySize
mov edx,ptrPrompt ; address of the prompt
mov esi,ptrArray
call WriteString ; display string
call Crlf
L1:
call ReadChar ; read character into EAX
mov [esi],eax ; store in arrayA
add esi,TYPE DWORD ; next character
loop L1
ret
PromptA ENDP
END
TITLE PromptB (_promptB.asm)
; Author: Francis Nguyen
; Date Created: 12/3/2010
; Last Modification Date: 12/3/2010
INCLUDE compare.inc
.code
;-----------------------------------------------------
PromptB PROC,
ptrPrompt:PTR BYTE, ; prompt string
arraySize:DWORD, ; size of the array
ptrArray:PTR DWORD ; points to the array
; Prompts the user for an arrayB of characters and fills
; the array with the user's input.
; Receives:
; ptrPrompt:PTR BYTE ; prompt string
; arraySize:DWORD ; size of the array
; ptrArray:PTR DWORD ; pointer to array
; Returns: nothing
;-----------------------------------------------------
mov ecx,arraySize
mov edx,ptrPrompt ; address of the prompt
mov esi,ptrArray
call WriteString ; display string
call Crlf
L1:
call ReadChar ; read character into EAX
mov [esi],eax ; store in arrayB
add esi,TYPE DWORD ; next character
loop L1
ret
PromptB ENDP
END
TITLE DisplayA (_displayA.asm)
; Author: Francis Nguyen
; Date Created: 12/3/2010
; Last Modification Date: 12/3/2010
INCLUDE compare.inc
.code
;-----------------------------------------------------
DisplayA PROC,
ptrPrompt:PTR BYTE, ; prompt string
arraySize:DWORD, ; size of the array
ptrArray:PTR DWORD ; points to the array
; Displays the arrayA on the console.
; Receives:
; ptrPrompt ; prompt string
; arraySize ; size of array (DWORD)
; ptrArray ; pointer to array
; Returns: EAX = arrayA
;-----------------------------------------------------
mov esi,ptrArray
mov ecx,arraySize
mov edx,ptrPrompt ; address of the prompt
call WriteString ; display string
call Crlf
L1:
mov eax,[esi]
call WriteChar ; display EAX
call Crlf
add esi,TYPE DWORD
loop L1
ret
DisplayA ENDP
END
TITLE DisplayB (_displayB.asm)
; Author: Francis Nguyen
; Date Created: 12/3/2010
; Last Modification Date: 12/3/2010
INCLUDE compare.inc
.code
;-----------------------------------------------------
DisplayB PROC,
ptrPrompt:PTR BYTE, ; prompt string
arraySize:DWORD, ; size of the array
ptrArray:PTR DWORD ; points to the array
; Displays the arrayB on the console.
; Receives:
; ptrPrompt ; prompt string
; arraySize ; size of array (DWORD)
; ptrArray ; pointer to array
; Returns: EAX = arrayB
;-----------------------------------------------------
mov esi,ptrArray
mov ecx,arraySize
mov edx,ptrPrompt ; address of the prompt
call WriteString ; display string
call Crlf
L1:
mov eax,[esi]
call WriteChar ; display EAX
call Crlf
add esi,TYPE DWORD
loop L1
ret
DisplayB ENDP
END
TITLE Compare (_compare.asm)
; Author: Francis Nguyen
; Date Created: 12/3/2010
; Last Modification Date: 12/3/2010
INCLUDE compare.inc
.code
;-----------------------------------------------------
Compare PROC,
arraySize:DWORD, ; size of the array
ptrArrayA:PTR DWORD, ; points to the array
ptrArrayB:PTR DWORD, ; points to the array
ptrPromptEqual:PTR BYTE, ; prompt string
ptrPromptNotEqual:PTR BYTE ; prompt string
; Compare the two arrays of 32-bit characters.
; Receives:
; arraySize ; size of array (DWORD)
; ptrArrayA ; pointer to arrayA
; ptrArrayB ; pointer to arrayB
; ptrPromptEqual ; prompt equal string
; ptrPromptNotEqual ; prompt notEqual string
;-----------------------------------------------------
mov esi,ptrArrayA
mov edi,ptrArrayB
mov ecx,arraySize
mov edx,0
L1:
mov eax,[esi]
mov ebx,[edi]
.IF (eax == ebx)
add edx, 1
.ENDIF
add esi,TYPE DWORD
add edi,TYPE DWORD
loop L1
mov ecx,arraySize
.IF (edx == ecx)
mov edx,ptrPromptEqual ; "The two arrays are equal."
call WriteString; ; display message
call Crlf ; go to next output line
.ELSE
mov edx,ptrPromptNotEqual; "The two arrays are not equal."
call WriteString; ; display message
call Crlf ; go to next output line
.ENDIF
;--------------------------------------------------------------------
;L1:
; mov eax,arrayA[esi]
; mov eax,dword ptr arrayA[esi]
; mov ebx,arrayB[edi]
; mov ebx,dword ptr arrayB[edi]
; cmp eax,ebx ; .IF (eax == ebx)
; jne
; add edx, 1
; add esi,TYPE DWORD
; loop L1
;mov ecx,CHAR_COUNT
;cmp edx,ecx ; .IF (edx == ecx)
;jne
;mov edx,OFFSET equal ; "The two arrays are equal."
;mov edx,offset equal
;call WriteString; ; display message
;call Crlf ; go to next output line
;jmp ; .ELSE
;mov edx,OFFSET notEqual ; "The two arrays are not equal."
;mov edx,offset notEqual
;call WriteString; ; display message
;call Crlf ; go to next output line
;--------------------------------------------------------------------
ret
Compare ENDP
END
Please enter 3 characters for the first array: Please enter 3 characters for the second array: Array A: a b c Array B: a b c The two arrays are equal. Press any key to continue . . . |