Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

LAB 11 (22k-4136)

Task 1:
INCLUDE Irvine32.inc
.data

string1 byte "127&j~3#^&*#*#45^",0


prompt byte "# found at position: ",0

.code
main PROC

call Scan_Str

exit
main ENDP

Scan_Str PROC

mov edi,OFFSET string1


mov al,'#'
mov ecx,LENGTHOF string1
cld
repne scasb
jnz bottom
dec edi

mov eax,edi
mov ebx,offset string1

sub eax,ebx
mov edx,offset prompt
call writestring
call writeDec

bottom:

ret
Scan_Str ENDP

END main
Task 2:
INCLUDE Irvine32.inc
.data

string1 byte "127&j~3#^&*#*#45^",0


prompt byte "# found at position: ",0

.code
Scan_Str PROC string1OFFSET:PTR BYTE,promptOFFSET:PTR BYTE,arham:BYTE
mov edi,string1OFFSET
mov eax,0
mov al,arham
mov ecx,LENGTHOF string1
cld
repne scasb
jnz bottom
dec edi

mov eax,edi
mov ebx,offset string1

sub eax,ebx
mov edx,promptOFFSET

call writestring
call writeDec

bottom:

ret
Scan_Str ENDP
main PROC
INVOKE Scan_Str,ADDR string1,ADDR prompt,'#'

exit
main ENDP

END main
Task 3:
INCLUDE Irvine32.inc
INCLUDE macros.inc

.data

str1 byte "127&j~3#^&*#*#45^",0


str2 byte "127&j~3#^&*#*#45^",0

.code
IsCompare PROC str1OFFSET:PTR BYTE,str2OFFSET:PTR BYTE,len:PTR DWORD

mov esi,str1OFFSET
mov edi,str2OFFSET
mov ecx,len

repe cmpsb
jnz notSame
mwrite "The strings are same"
jmp bottom
notSame:
mwrite "The strings are different"

bottom:
ret
IsCompare ENDP

main PROC

INVOKE IsCompare,ADDR str1,ADDR str2,LENGTHOF str1

exit
main ENDP

END main
Task 4:
INCLUDE Irvine32.inc
INCLUDE macros.inc

.data

str1 byte "127&j~3#^&*#*#45^",0


str2 byte LENGTHOF str1 DUP(?),0

.code
Str_Reverse PROC str1OFFSET:PTR BYTE,str2OFFSET:PTR BYTE,len:PTR DWORD

mov esi,str1OFFSET
mov edi,str2OFFSET
mov ecx,len
sub ecx,2
L1:

mov al,[esi+ecx]
stosb
Loop L1
mov al,[esi]
stosb

mov edx,str2OFFSET
call writeString

ret
Str_Reverse ENDP

main PROC

mov edx,offset str1


call writestring
call crlf

INVOKE Str_Reverse,ADDR str1,ADDR str2,LENGTHOF str1

exit
main ENDP

END main
Task 5:
INCLUDE Irvine32.inc
.data
arr BYTE 1,2,3,4,5,6,7,8,9,10
multiplier DWORD 5
prompt BYTE " ",0

.code
main PROC
cld
push LENGTHOF arr
push OFFSET arr
push multiplier

mov ecx,lengthof arr


mov esi,0
L1:
movzx eax,arr[esi]
call writeDec
inc esi
mov edx,OFFSET prompt
call writeString
Loop L1

call crlf

call LOAD

mov ecx,lengthof arr


mov esi,0
L2:
movzx eax,arr[esi]
call writeDec
inc esi
mov edx,OFFSET prompt
call writeString
Loop L2

exit
main ENDP

LOAD PROC
enter 0,0
mov ecx,[ebp+16]
mov esi,[ebp+12]
mov ebx,[ebp+8]
mov edi,esi
cld
L1:
Lodsb
mul ebx
Stosb

Loop L1
leave
ret
LOAD ENDP
END main

Task 6:
INCLUDE Irvine32.inc
INCLUDE macros.inc

.data
str1 BYTE "AADDDCFBBCEE",0
freqTable DWORD 256 DUP(0)

.code
Get_frequencies PROC str1OFFSET:PTR BYTE, freqTableOFFSET:PTR DWORD
mov ecx, 0
mov esi, str1OFFSET

top:
mov al, [esi]
cmp al, 0
je quit
inc ecx
inc esi
jmp top
quit:

mov ebx, ecx


mov esi, str1OFFSET
mov edi, freqTableOFFSET
L1:
mov al, [esi]
movzx eax, al
mov edx, 4
mul edx
add eax, edi
inc DWORD PTR [eax]
inc esi
Loop L1

ret
Get_frequencies ENDP

main PROC
INVOKE Get_frequencies, ADDR str1, ADDR freqTable

mov ecx, 256


mov esi, OFFSET freqTable
mov edi, 0
mov dl, 0

L2:
mov eax, [esi + edi]
cmp eax, 0
je jump

mov al, dl
call WriteChar
mWrite " = "
mov eax, [esi + edi]
call WriteDec
mWrite " , "

jump:
add edi, 4
inc dl
Loop L2

INVOKE ExitProcess, 0
main ENDP

END main

You might also like