In this homework, you are asked to write two functions to process part of a Shak
ID: 673657 • Letter: I
Question
In this homework, you are asked to write two functions to process part of a Shakespeare play I copied from http://www.william-shakespeare.info/act2-script-text-henry-vi-part1.htm. I have provided the skeleton of the code at the end of this description of the homework.
strcmp (50 points): Accepts in $a0 and $a1 the addresses of two asciiz strings. Returns in $v0 1 if the two strings are identical for all characters, case insensitive, before the last “0” in the second string; otherwise returns 0.
wordcount (50 points): Accepts in $a0 and $a1 the addresses of two asciiz strings, called str0 and str1. Returns in $v0 the number of times str1 appears in str0. It must call strcmp. An appearance of str1 in str0 is case insensitive, and is counted as long as a segment of str0 has the same ascii values as str1. For example, if str0 is “ABABA” and str1 is “aBa”, the number of appearances is 2.
--------------------------------------------------------------------------------------------------------------
.data
dialog :.asciiz "BEDFORD
Coward of France! how much he wrongs his fame,
Despairing of his own arm's fortitude,
To join with witches and the help of hell!
BURGUNDY
Traitors have never other company.
But what's that Pucelle whom they term so pure?
TALBOT
A maid, they say.
BEDFORD
A maid! and be so martial!
BURGUNDY
Pray God she prove not masculine ere long,
If underneath the standard of the French
She carry armour as she hath begun.
TALBOT
Well, let them practise and converse with spirits:
God is our fortress, in whose conquering name
Let us resolve to scale their flinty bulwarks.
BEDFORD
Ascend, brave Talbot; we will follow thee.
TALBOT
Not all together: better far, I guess,
That we do make our entrance several ways;
That, if it chance the one of us do fail,
The other yet may rise against their force.
BEDFORD
Agreed: I'll to yond corner.
BURGUNDY
And I to this.
TALBOT
And here will Talbot mount, or make his grave.
Now, Salisbury, for thee, and for the right
Of English Henry, shall this night appear
How much in duty I am bound to both.
Sentinels
Arm! arm! the enemy doth make assault!
ALENCON
How now, my lords! what, all unready so?
BASTARD OF ORLEANS
Unready! ay, and glad we 'scaped so well.
REIGNIER
'Twas time, I trow, to wake and leave our beds,
Hearing alarums at our chamber-doors.
ALENCON
Of all exploits since first I follow'd arms,
Ne'er heard I of a warlike enterprise
More venturous or desperate than this.
BASTARD OF ORLEANS
I think this Talbot be a fiend of hell.
REIGNIER
If not of hell, the heavens, sure, favour him.
ALENCON
Here cometh Charles: I marvel how he sped.
BASTARD OF ORLEANS
Tut, holy Joan was his defensive guard.
Enter CHARLES and JOAN LA PUCELLE
CHARLES
Is this thy cunning, thou deceitful dame?
Didst thou at first, to flatter us withal,
Make us partakers of a little gain,
That now our loss might be ten times so much?
JOAN LA PUCELLE
Wherefore is Charles impatient with his friend!
At all times will you have my power alike?
Sleeping or waking must I still prevail,
Or will you blame and lay the fault on me?
Improvident soldiers! had your watch been good,
This sudden mischief never could have fall'n.
CHARLES
Duke of Alencon, this was your default,
That, being captain of the watch to-night,
Did look no better to that weighty charge.
ALENCON
Had all your quarters been as safely kept
As that whereof I had the government,
We had not been thus shamefully surprised.
BASTARD OF ORLEANS
Mine was secure.
REIGNIER
And so was mine, my lord.
CHARLES
And, for myself, most part of all this night,
Within her quarter and mine own precinct
I was employ'd in passing to and fro,
About relieving of the sentinels:
Then how or which way should they first break in?
JOAN LA PUCELLE
Question, my lords, no further of the case,
How or which way: 'tis sure they found some place
But weakly guarded, where the breach was made.
And now there rests no other shift but this;
To gather our soldiers, scatter'd and dispersed,
And lay new platforms to endamage them.
Soldier
I'll be so bold to take what they have left.
The cry of Talbot serves me for a sword;
For I have loaden me with many spoils,
Using no other weapon but his name.
Exit
SCENE II. Orleans. Within the town.
Enter TALBOT, BEDFORD, BURGUNDY, a Captain, and others
BEDFORD
The day begins to break, and night is fled,
Whose pitchy mantle over-veil'd the earth.
Here sound retreat, and cease our hot pursuit.
Retreat sounded
TALBOT
Bring forth the body of old Salisbury,
And here advance it in the market-place,
The middle centre of this cursed town.
Now have I paid my vow unto his soul;
For every drop of blood was drawn from him,
There hath at least five Frenchmen died tonight.
And that hereafter ages may behold
What ruin happen'd in revenge of him,
Within their chiefest temple I'll erect
A tomb, wherein his corpse shall be interr'd:
Upon the which, that every one may read,
Shall be engraved the sack of Orleans,
The treacherous manner of his mournful death
And what a terror he had been to France.
But, lords, in all our bloody massacre,
I muse we met not with the Dauphin's grace,
His new-come champion, virtuous Joan of Arc,
Nor any of his false confederates.
BEDFORD
'Tis thought, Lord Talbot, when the fight began,
Roused on the sudden from their drowsy beds,
They did amongst the troops of armed men
Leap o'er the walls for refuge in the field.
BURGUNDY
Myself, as far as I could well discern
For smoke and dusky vapours of the night,
Am sure I scared the Dauphin and his trull,
When arm in arm they both came swiftly running,
Like to a pair of loving turtle-doves
That could not live asunder day or night.
After that things are set in order here,
We'll follow them with all the power we have.
Enter a Messenger
Messenger
All hail, my lords! which of this princely train
Call ye the warlike Talbot, for his acts
So much applauded through the realm of France?
TALBOT
Here is the Talbot: who would speak with him?
Messenger
The virtuous lady, Countess of Auvergne,
With modesty admiring thy renown,
By me entreats, great lord, thou wouldst vouchsafe
To visit her poor castle where she lies,
That she may boast she hath beheld the man
Whose glory fills the world with loud report.
BURGUNDY
Is it even so? Nay, then, I see our wars
Will turn unto a peaceful comic sport,
When ladies crave to be encounter'd with.
You may not, my lord, despise her gentle suit.
TALBOT
Ne'er trust me then; for when a world of men
Could not prevail with all their oratory,
Yet hath a woman's kindness over-ruled:
And therefore tell her I return great thanks,
And in submission will attend on her.
Will not your honours bear me company?
BEDFORD
No, truly; it is more than manners will:
And I have heard it said, unbidden guests
Are often welcomest when they are gone.
TALBOT
Well then, alone, since there's no remedy,
I mean to prove this lady's courtesy.
Come hither, captain.
"
namehere:.asciiz "BEDFORD"
.text
.globl main
main:la $a0, dialog
la $a1, namehere
jal wordcount
ori $a0,$v0, 0
li $v0,1 # print an integer in $a0
syscall
done:li $v0, 10 # Exit
syscall
#------------------------------------------------
wordcount:
jr $ra
#------------------------------------------------
#------------------------------------------------
strcmp:
jr $ra
#------------------------------------------------
Explanation / Answer
.Ltext0:
.globl funcStrCmp
funcStrCmp:
.LFB0:
.cfi_startproc
0000 55 pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
0001 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
0004 4883EC10 subq $16, %rsp
0008 48897DF8 movq %rdi, -8(%rbp)
000c 488975F0 movq %rsi, -16(%rbp)
0010 488B55F0 movq -16(%rbp), %rdx
0014 488B45F8 movq -8(%rbp), %rax
0018 4889D6 movq %rdx, %rsi
001b 4889C7 movq %rax, %rdi
001e E8000000 call strcmp
00
0023 85C0 testl %eax, %eax
0025 7507 jne .L2
0027 B8010000 movl $1, %eax
00
002c EB05 jmp .L3
.L2:
002e B8000000 movl $0, %eax
00
.L3:
0033 C9 leave
.cfi_def_cfa 7, 8
0034 C3 ret
.cfi_endproc
.LFE0:
.globl funcWordCount
funcWordCount:
.LFB1:
.cfi_startproc
0035 55 pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
0036 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
0039 4883EC20 subq $32, %rsp
003d 48897DE8 movq %rdi, -24(%rbp)
0041 488975E0 movq %rsi, -32(%rbp)
0045 C745FC00 movl $0, -4(%rbp)
000000
004c 488B55E0 movq -32(%rbp), %rdx
0050 488B45E8 movq -24(%rbp), %rax
0054 4889D6 movq %rdx, %rsi
0057 4889C7 movq %rax, %rdi
005a E8000000 call strstr
00
005f 4885C0 testq %rax, %rax
0062 7404 je .L5
0064 8345FC01 addl $1, -4(%rbp)
.L5:
0068 8B45FC movl -4(%rbp), %eax
006b C9 leave
.cfi_def_cfa 7, 8
006c C3 ret
.cfi_endproc
.LFE1:
.section .rodata
.align 8
.LC0:
0000 42555247 .string "BURGUNDY Pray God she prove not masculine ere long, If underneath the standard of the Fre
554E4459
20507261
7920476F
64207368
0081 00000000 .align 8
000000
.LC1:
0088 42454446 .string "BEDFORD The day begins to break, and night is fled, Whose pitchy mantle over-veil'd the e
4F524420
54686520
64617920
62656769
.LC2:
0126 256400 .string "%d"
.text
.globl main
main:
.LFB2:
.cfi_startproc
006d 55 pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
006e 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
0071 53 pushq %rbx
0072 4883EC18 subq $24, %rsp
.cfi_offset 3, -24
0076 488B45E0 movq -32(%rbp), %rax
007a 48BB4255 movabsq $6432352295967675714, %rbx
5247554E
4459
0084 488918 movq %rbx, (%rax)
0087 48BB2054 movabsq $8245937438693938208, %rbx
72616974
6F72
0091 48895808 movq %rbx, 8(%rax)
0095 48BB7320 movabsq $7935454102541574259, %rbx
68617665
206E
009f 48895810 movq %rbx, 16(%rax)
00a3 48BB6576 movabsq $7526763062391830117, %rbx
6572206F
7468
00ad 48895818 movq %rbx, 24(%rax)
00b1 48BB6572 movabsq $7021232144242471525, %rbx
20636F6D
7061
00bb 48895820 movq %rbx, 32(%rax)
00bf 48BB6E79 movabsq $2338623033380338030, %rbx
2E204275
7420
00c9 48895828 movq %rbx, 40(%rax)
00cd 48BB7768 movabsq $8367814720947841143, %rbx
61742773
2074
00d7 48895830 movq %rbx, 48(%rax)
00db 48BF6861 movabsq $7305812007527407976, %rdi
74205075
6365
00e5 48897838 movq %rdi, 56(%rax)
00e9 48BB6C6C movabsq $7885636333402942572, %rbx
65207768
6F6D
00f3 48895840 movq %rbx, 64(%rax)
00f7 48BF2074 movabsq $7310503800893633568, %rdi
68657920
7465
0101 48897848 movq %rdi, 72(%rax)
0105 48BB726D movabsq $8462299362874125682, %rbx
20736F20
7075
010f 48895850 movq %rbx, 80(%rax)
0113 C7405872 movl $4154738, 88(%rax)
653F00
011a 488B45E0 movq -32(%rbp), %rax
011e 48C7C1FF movq $-1, %rcx
FFFFFF
0125 4889C2 movq %rax, %rdx
0128 B8000000 movl $0, %eax
00
012d 4889D7 movq %rdx, %rdi
0130 F2AE repnz scasb
0132 4889C8 movq %rcx, %rax
0135 48F7D0 notq %rax
0138 488D50FF leaq -1(%rax), %rdx
013c 488B45E0 movq -32(%rbp), %rax
0140 4801D0 addq %rdx, %rax
0143 48BF5441 movabsq $4692843511111500116, %rdi
4C424F54
2041
014d 488938 movq %rdi, (%rax)
0150 48BB206D movabsq $8367736917430725920, %rbx
6169642C
2074
015a 48895808 movq %rbx, 8(%rax)
015e 48BF6865 movabsq $3348814945020634472, %rdi
79207361
792E
0168 48897810 movq %rdi, 16(%rax)
016c 48BB2042 movabsq $4923084505881068064, %rbx
4544464F
5244
0176 48895818 movq %rbx, 24(%rax)
017a 48BF2041 movabsq $2406163968086262048, %rdi
206D6169
6421
0184 48897820 movq %rdi, 32(%rax)
0188 48BB2061 movabsq $2334379873124901152, %rbx
6E642062
6520
0192 48895828 movq %rbx, 40(%rax)
0196 48BF736F movabsq $7598824234049105779, %rdi
206D6172
7469
01a0 48897830 movq %rdi, 48(%rax)
01a4 C7403861 movl $539061345, 56(%rax)
6C2120
01ab C6403C00 movb $0, 60(%rax)
01af 488B45E0 movq -32(%rbp), %rax
01b3 48C7C1FF movq $-1, %rcx
FFFFFF
01ba 4889C2 movq %rax, %rdx
01bd B8000000 movl $0, %eax
00
01c2 4889D7 movq %rdx, %rdi
01c5 F2AE repnz scasb
01c7 4889C8 movq %rcx, %rax
01ca 48F7D0 notq %rax
01cd 488D50FF leaq -1(%rax), %rdx
01d1 488B45E0 movq -32(%rbp), %rax
01d5 4801D0 addq %rdx, %rax
01d8 BA000000 movl $.LC0, %edx
00
01dd 41B88100 movl $129, %r8d
0000
01e3 4889C1 movq %rax, %rcx
01e6 83E101 andl $1, %ecx
01e9 4885C9 testq %rcx, %rcx
01ec 7411 je .L8
01ee 0FB60A movzbl (%rdx), %ecx
01f1 8808 movb %cl, (%rax)
01f3 4883C001 addq $1, %rax
01f7 4883C201 addq $1, %rdx
01fb 4183E801 subl $1, %r8d
.L8:
01ff 4889C1 movq %rax, %rcx
0202 83E102 andl $2, %ecx
0205 4885C9 testq %rcx, %rcx
0208 7412 je .L9
020a 0FB70A movzwl (%rdx), %ecx
020d 668908 movw %cx, (%rax)
0210 4883C002 addq $2, %rax
0214 4883C202 addq $2, %rdx
0218 4183E802 subl $2, %r8d
.L9:
021c 4889C1 movq %rax, %rcx
021f 83E104 andl $4, %ecx
0222 4885C9 testq %rcx, %rcx
0225 7410 je .L10
0227 8B0A movl (%rdx), %ecx
0229 8908 movl %ecx, (%rax)
022b 4883C004 addq $4, %rax
022f 4883C204 addq $4, %rdx
0233 4183E804 subl $4, %r8d
.L10:
0237 4489C1 movl %r8d, %ecx
023a C1E903 shrl $3, %ecx
023d 89C9 movl %ecx, %ecx
023f 4889C7 movq %rax, %rdi
0242 4889D6 movq %rdx, %rsi
0245 F348A5 rep movsq
0248 4889F2 movq %rsi, %rdx
024b 4889F8 movq %rdi, %rax
024e B9000000 movl $0, %ecx
00
0253 4489C6 movl %r8d, %esi
0256 83E604 andl $4, %esi
0259 85F6 testl %esi, %esi
025b 7408 je .L11
025d 8B32 movl (%rdx), %esi
025f 8930 movl %esi, (%rax)
0261 4883C104 addq $4, %rcx
.L11:
0265 4489C6 movl %r8d, %esi
0268 83E602 andl $2, %esi
026b 85F6 testl %esi, %esi
026d 740C je .L12
026f 0FB7340A movzwl (%rdx,%rcx), %esi
0273 66893408 movw %si, (%rax,%rcx)
0277 4883C102 addq $2, %rcx
.L12:
027b 4489C6 movl %r8d, %esi
027e 83E601 andl $1, %esi
0281 85F6 testl %esi, %esi
0283 7407 je .L13
0285 0FB6140A movzbl (%rdx,%rcx), %edx
0289 881408 movb %dl, (%rax,%rcx)
.L13:
028c 488B45E8 movq -24(%rbp), %rax
0290 BA000000 movl $.LC1, %edx
00
0295 41B89E00 movl $158, %r8d
0000
029b 4889C1 movq %rax, %rcx
029e 83E101 andl $1, %ecx
02a1 4885C9 testq %rcx, %rcx
02a4 7411 je .L14
02a6 0FB60A movzbl (%rdx), %ecx
02a9 8808 movb %cl, (%rax)
02ab 4883C001 addq $1, %rax
02af 4883C201 addq $1, %rdx
02b3 4183E801 subl $1, %r8d
.L14:
02b7 4889C1 movq %rax, %rcx
02ba 83E102 andl $2, %ecx
02bd 4885C9 testq %rcx, %rcx
02c0 7412 je .L15
02c2 0FB70A movzwl (%rdx), %ecx
02c5 668908 movw %cx, (%rax)
02c8 4883C002 addq $2, %rax
02cc 4883C202 addq $2, %rdx
02d0 4183E802 subl $2, %r8d
.L15:
02d4 4889C1 movq %rax, %rcx
02d7 83E104 andl $4, %ecx
02da 4885C9 testq %rcx, %rcx
02dd 7410 je .L16
02df 8B0A movl (%rdx), %ecx
02e1 8908 movl %ecx, (%rax)
02e3 4883C004 addq $4, %rax
02e7 4883C204 addq $4, %rdx
02eb 4183E804 subl $4, %r8d
.L16:
02ef 4489C1 movl %r8d, %ecx
02f2 C1E903 shrl $3, %ecx
02f5 89C9 movl %ecx, %ecx
02f7 4889C7 movq %rax, %rdi
02fa 4889D6 movq %rdx, %rsi
02fd F348A5 rep movsq
0300 4889F2 movq %rsi, %rdx
0303 4889F8 movq %rdi, %rax
0306 B9000000 movl $0, %ecx
00
030b 4489C6 movl %r8d, %esi
030e 83E604 andl $4, %esi
0311 85F6 testl %esi, %esi
0313 7408 je .L17
0315 8B32 movl (%rdx), %esi
0317 8930 movl %esi, (%rax)
0319 4883C104 addq $4, %rcx
.L17:
031d 4489C6 movl %r8d, %esi
0320 83E602 andl $2, %esi
0323 85F6 testl %esi, %esi
0325 740C je .L18
0327 0FB7340A movzwl (%rdx,%rcx), %esi
032b 66893408 movw %si, (%rax,%rcx)
032f 4883C102 addq $2, %rcx
.L18:
0333 4489C6 movl %r8d, %esi
0336 83E601 andl $1, %esi
0339 85F6 testl %esi, %esi
033b 7407 je .L19
033d 0FB6140A movzbl (%rdx,%rcx), %edx
0341 881408 movb %dl, (%rax,%rcx)
.L19:
0344 488B45E8 movq -24(%rbp), %rax
0348 48C7C1FF movq $-1, %rcx
FFFFFF
034f 4889C2 movq %rax, %rdx
0352 B8000000 movl $0, %eax
00
0357 4889D7 movq %rdx, %rdi
035a F2AE repnz scasb
035c 4889C8 movq %rcx, %rax
035f 48F7D0 notq %rax
0362 488D50FF leaq -1(%rax), %rdx
0366 488B45E8 movq -24(%rbp), %rax
036a 4801D0 addq %rdx, %rax
036d 48BB5441 movabsq $4764901105149428052, %rbx
4C424F54
2042
0377 488918 movq %rbx, (%rax)
037a 48BF7269 movabsq $8245921732098943346, %rdi
6E672066
6F72
0384 48897808 movq %rdi, 8(%rax)
0388 48BB7468 movabsq $7070762914270963828, %rbx
20746865
2062
0392 48895810 movq %rbx, 16(%rax)
0396 48BF6F64 movabsq $8007512764936971375, %rdi
79206F66
206F
03a0 48897818 movq %rdi, 24(%rax)
03a4 48BB6C64 movabsq $8316297352178590828, %rbx
2053616C
6973
03ae 48895820 movq %rbx, 32(%rax)
03b2 48BF6275 movabsq $7944666593046459746, %rdi
72792C20
416E
03bc 48897828 movq %rdi, 40(%rax)
03c0 48BB6420 movabsq $6998705362935750756, %rbx
68657265
2061
03ca 48895830 movq %rbx, 48(%rax)
03ce 48BF6476 movabsq $7575166050965223012, %rdi
616E6365
2069
03d8 48897838 movq %rdi, 56(%rax)
03dc 48BB7420 movabsq $7307218078048788596, %rbx
696E2074
6865
03e6 48895840 movq %rbx, 64(%rax)
03ea 48BF206D movabsq $3275354341160086816, %rdi
61726B65
742D
03f4 48897848 movq %rdi, 72(%rax)
03f8 48BB706C movabsq $6061893912411335792, %rbx
6163652C
2054
0402 48895850 movq %rbx, 80(%rax)
0406 48BF6865 movabsq $7810478057732466024, %rdi
206D6964
646C
0410 48897858 movq %rdi, 88(%rax)
0414 48BB6520 movabsq $7310033162671956069, %rbx
63656E74
7265
041e 48895860 movq %rbx, 96(%rax)
0422 48BF206F movabsq $8316293034885410592, %rdi
66207468
6973
042c 48897868 movq %rdi, 104(%rax)
0430 48BB2063 movabsq $2334102053400699680, %rbx
75727365
6420
043a 48895870 movq %rbx, 112(%rax)
043e 48BF746F movabsq $9042583048646516, %rdi
776E2E20
2000
0448 48897878 movq %rdi, 120(%rax)
044c 488B55E8 movq -24(%rbp), %rdx
0450 488B45E0 movq -32(%rbp), %rax
0454 4889D6 movq %rdx, %rsi
0457 4889C7 movq %rax, %rdi
045a E8000000 call funcWordCount
00
045f 89C6 movl %eax, %esi
0461 BF000000 movl $.LC2, %edi
00
0466 B8000000 movl $0, %eax
00
046b E8000000 call printf
00
0470 B8000000 movl $0, %eax
00
0475 4883C418 addq $24, %rsp
0479 5B popq %rbx
047a 5D popq %rbp
.cfi_def_cfa 7, 8
047b C3 ret
.cfi_endproc
.LFE2:
.Letext0:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.