0% found this document useful (0 votes)
2 views

Coal lab 12

The document contains several assembly language programs that demonstrate string manipulation and array operations using the Irvine32 library. Key functionalities include scanning for a character in a string, comparing two strings for equality, reversing a string, and multiplying elements of an array by a specified number. Each program is structured with a main procedure and respective subroutines for specific tasks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Coal lab 12

The document contains several assembly language programs that demonstrate string manipulation and array operations using the Irvine32 library. Key functionalities include scanning for a character in a string, comparing two strings for equality, reversing a string, and multiplying elements of an array by a specified number. Each program is structured with a main procedure and respective subroutines for specific tasks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Question 1:

include irvine32.inc
.data
str1 BYTE '127&j~3#^&*#*#45^',0
prompt byte "Character Found At Index : ", 0
.code
main proc

call Scan_String
lea edx,prompt
call writestring
mov eax,edi
call writeint

exit
main endp

Scan_String PROC
lea edi,str1
mov al,'#'
mov ecx,lengthof str1
cld
repne scasb
jnz notfound
mov edx,offset str1
sub edi,edx
dec edi
ret

notfound:
mov edi,-1
ret
Scan_String endp
end mainOUTPUT

QUESTION :2

include irvine32.inc
.data
str1 BYTE '127&j~3#^&*#*#45^',0
prompt BYTE "Character Found At Index : ", 0
char byte '#',0
.code
main proc
push offset str1
push '#'
push lengthof str1
call Scan_String
lea edx,prompt
call writestring
mov eax,edi
call writeint
exit
main endp

Scan_String PROC

push ebp
mov ebp,esp
mov edi,[ebp+16]
mov al,[ebp+12]
mov ecx,[ebp+8]
cld
repne scasb
jnz notfound
mov edx,[ebp+16]
sub edi,edx
dec edi
pop ebp
ret

notfound:
mov edi,-1
pop ebp
ret
Scan_String endp
end main

QUESTION 3

include irvine32.inc

.data

str1 BYTE "coal Lab 11" ,0


str2 BYTE "Lab 11" ,0
prompt1 BYTE "Both strings are equal", 0
prompt2 BYTE "Strings are not equal"

IsCompare proto, :dword, :dword

.code

main proc
invoke IsCompare, addr str1, addr str2

exit

main endp
IsCompare proc, string1:dword, string2:dword

mov esi,string1
mov edi,string2
L1:
mov al,[esi]
mov dl,[edi]
cmp al,0
jne L2

cmp dl,0
jne L2

; both strings ended


jmp L3

L2: inc esi


inc edi
cmp al , dl
je L1

L3:

jnz notequal1

mov edx, offset prompt1


call WriteString
jmp endd
notequal1:
mov edx, offset prompt2
call WriteString

endd:
call crlf
ret
IsCompare endp

end main

QUESTION 4

include irvine32.inc

.data
str1 BYTE "coal Lab 11" ,0
str2 BYTE lengthof str1 dup(?)

Str_Reverse proto, :dword, :dword

.code

main proc
mov edx, offset str1
call writestring
call crlf

invoke Str_Reverse, addr str1, addr str2

call crlf
call writestring ; writing reverse string
call crlf

exit

main endp

Str_Reverse proc, string1:dword, reverse_string:dword

mov esi,string1

mov ecx, lengthof str1


add esi, ecx
sub esi,2

mov edi, reverse_string


cld
L1:
mov al, [esi]
dec esi
stosb
loop l1

mov edx, reverse_string

ret
Str_Reverse endp

end main

QUESTION 5

INCLUDE Irvine32.inc
.data

array byte 1,3,5,7,9,11,19,17

number byte 3

Multiply_array proto, :dword, :byte


.code

main PROC

invoke Multiply_array, offset array, number

exit
main ENDP

Multiply_array proc, arr:dword, no:byte

mov ecx, lengthof array


mov esi, arr
mov edi, esi
cld
L1:
lodsb
mul no
stosb
loop L1

mov esi, offset array


mov ecx, lengthof array
;mov esi, arr
L2:
mov al, ' '
call writechar
movzx eax, byte ptr [esi]
call Writedec
inc esi
loop l2
call crlf
call crlf
ret

Multiply_array endp

END main

You might also like