DON\'T COPY PREVIOUS ANSWERS BECAUSE THEY\'RE NOT WORKING Write the equivalent i
ID: 3911283 • Letter: D
Question
DON'T COPY PREVIOUS ANSWERS BECAUSE THEY'RE NOT WORKING
Write the equivalent instructions for the rep cmpsb and rep scasb below. This must be in inline assembly for credit.
// cmpsb example: find a character in a string
lea edi,s2 // move the address of source into the esi register
mov ecx,length s2 // move the length of the source string into ecx (counter)
cld // set the direction flag to UP
mov eax,'b' // set up the eax register for the compare
repne scasb // compare the al register to the value at [edi] and repeat while not
// until ecx = 0
je equal // jump if character found, i.e. al was equal to [edi]
nop // if we go here the strings are NOT equal
equal: nop // nop: doesn't do anything but waste time
// cmpsb example: compare two strings
lea esi,s1 // move the address of source into the esi register
lea edi,s2 // move the address of dest into the edi register
mov ecx,length s1 // move the length of the source string into ecx (counter)
cld // set the direction flag to UP
repe cmpsb
jne notequ // jump if strings not equal
nop // if we go here the strings are equal
notequ: nop
Copy and paste all your lines of code, including the C code into Blackboard. If I copy your code into visual studio, it should execute without modification. Do not attach a file.
Be sure to comment every line for credit.
Explanation / Answer
1: find a character in a string taken as an array
cr equ 13
lf equ 10
data segment
prompt1 db cr,lf,'enter any string :',0
promp2 db cr,lf,'enter any character :',0
promp3 db cr,lf,0
promp4 db 10,13,'character not found in the given string'
promp5 db ' character(s) found in the given string '
char db ?
count db 0
parameter1 label byte
m1 db 0ffh
l db ? ;uninitialised
p11 db 0ffh dup ('$')
data ends
output macro msg ;used for display on screen similar to printf in c language
mov ah,9
lea dx,msg
int 21h
endm
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
output prompt1
lea dx,parameter1
mov ah,0ah
int 21h
output promp2
mov ah,1
int 21h
mov char,al
output promp3
lea si,p11
mov cl,l
mov ch,0
check:
mov al,[si]
cmp char,al
jne next
inc count
next:
inc si
loop check
cmp count,0
je notfound
output promp3
mov dl,count
add dl,30h
mov ah,2
int 21h
output promp5
jmp exit
notfound:
output promp4
exit: mov ah,4ch
int 21h
code ends
end start
2.Compare two strings
Str1 dw 40 dup(?)
Output:enter first string
inputs str1,40
Output:enter second string
inputs str2,40
lea si,str1
lea di,str2
cld
repe cmpsw
jz label1
strings nt equal
jmp quit
label1: strings equal
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.