You are on page 1of 7

LAB 11

MUHAMMAD REHAN KHAN


21K-3172
BCS-3A
LAB 11

TASK 2
INCLUDE Irvine32.inc
.data
MyArray BYTE "127&j~3#^&*#*#45^",0
result BYTE "Index of The Charcater is: ",0

.code
main PROC

PUSH OFFSET MyArray


PUSH LENGTHOF MyArray
call Scan_String

exit
main ENDP

Scan_String PROC
PUSH ebp
mov ebp,esp
mov edi,[ebp+12]
mov ecx,[ebp+8]
mov ebx,[ebp+8]
mov eax,0
mov al,'#'
cld
repne scasb
jnz skip
sub ebx,ecx
dec ebx
mov edx,OFFSET result
call WriteString
mov eax, ebx
call WriteDec
skip:
POP ebp
ret 8
Scan_String ENDP
End MAIN
LAB 11

TASK 2
INCLUDE Irvine32.inc
.data
str1 BYTE "127&j~3#^&*#*#45^",0
msg BYTE "Enter Character to find: ",0
msg1 byte "Character found at index: ",0
.code
main PROC
push offset str1
push lengthof str1
mov edx,offset msg
call writestring
call scan_string
exit
main ENDP
scan_string PROC
push ebp
mov ebp,esp
mov edi,[ebp+12]
call readchar
call writechar
call crlf
cld
mov ecx,[ebp+8]
repne scasb
jnz _End
mov eax,[ebp+8]
sub eax,ecx
dec eax
mov edx,offset msg1
call writestring
call writedec

_End:
pop ebp
ret
scan_string ENDP
END Main
LAB 11

TASK 3
INCLUDE Irvine32.inc
.data
str1 BYTE "ab",0
str2 BYTE "abc",0
msg1 byte "soucre is bigger",0
msg2 byte "target is bigger",0
.code
isCompare PROTO ptr1:dword , ptr2:dword
main PROC
invoke isCompare, addr str1,addr str2
exit
main ENDP
isCompare PROC ptr1:dword , ptr2 :dword
mov esi,ptr1
mov edi,ptr2
invoke str_compare,addr str1 ,addr str2
JA source
mov edx,offset msg2
call writestring
jmp _end
source:
mov edx,offset msg1
call writestring
call crlf
_end:
ret
isCompare ENDP
END Main
LAB 11

TASK 4
INCLUDE irvine32.inc
.data
msg BYTE "COAL",0
.code
str_reverse PROTO ptr1:dword, a:dword
main PROC
invoke str_reverse, addr msg ,lengthof msg
mov ecx,lengthof msg
mov eax,0
mov esi,offset msg
l1:
mov al,[esi]
inc esi
call writechar
loop l1

exit
main ENDP
str_reverse PROC ptr1:dword, a:dword
mov esi,ptr1
mov ecx,a
l1:
push [esi]
inc esi
loop l1
mov ecx,a
mov esi,ptr1
l2:
pop [esi]
inc esi
loop l2
ret
str_reverse ENDP
END main
LAB 11

TASK 5
INCLUDE irvine32.inc
.data
arr dword 1,2,3,4,5
msg byte "Enter Byte Number: ",0
.code
load PROTO ptr1:dword, a:dword
main PROC
mov edx,offset msg
call writestring
call readdec
invoke load, addr arr , eax
exit
main ENDP
load PROC ptr1:dword, a:dword
mov esi,ptr1
mov eax,a
mov ecx,4
mul ecx
mov ecx,eax
mov eax,[esi+ecx]
call writedec
ret
load ENDP
END main
LAB 11

TASK 6
INCLUDE irvine32.inc
.data
target byte "AAEBDCFBBC",0
freqTable DWORD 256 DUP(0)
space byte " ",0
.code
Get_Frequencies PROTO ptr1:dword, ptable:dword
main PROC
invoke Get_Frequencies, addr target,addr freqTable
mov ecx,lengthof freqTable
mov esi,offset freqTable
l1:
mov eax,[esi]
call writedec
mov edx,offset space
call writestring
add esi, type freqTable
loop l1
exit
main ENDP
Get_Frequencies PROC ptr1:dword, ptable:dword
mov esi,ptr1
mov edi,ptable
cld
l1:
mov eax,0
lodsb
cmp al,0
je _exit
shl eax,2
inc dword ptr [edi+eax]
loop l1
_exit:
ret
Get_Frequencies ENDP
END main

You might also like