Assembly ATT X86程序集:警告:未终止的字符串;从gcc插入换行符
我正在用X86 AT&T汇编编写一些代码,用于类赋值。我单独测试了所有函数,它们完全按照预期工作,但出于某种原因,我在标题中对代码中的每一行都给出了警告。由于单独的函数在放入它们自己的文件时被编译,除了函数之外什么都没有,所以我不知道这里到底出了什么问题。请帮忙 我是在14.04 Ubuntu上写的Assembly ATT X86程序集:警告:未终止的字符串;从gcc插入换行符,assembly,gcc-warning,att,x86,Assembly,Gcc Warning,Att,X86,我正在用X86 AT&T汇编编写一些代码,用于类赋值。我单独测试了所有函数,它们完全按照预期工作,但出于某种原因,我在标题中对代码中的每一行都给出了警告。由于单独的函数在放入它们自己的文件时被编译,除了函数之外什么都没有,所以我不知道这里到底出了什么问题。请帮忙 我是在14.04 Ubuntu上写的 gcc -m32 -c pstring.s pstring.s: Assembler messages: pstring.s: Warning: end of file in string; '"'
gcc -m32 -c pstring.s
pstring.s: Assembler messages:
pstring.s: Warning: end of file in string; '"' inserted
pstring.s:3: Warning: unterminated string; newline inserted
pstring.s:4: Warning: unterminated string; newline inserted
pstring.s:5: Warning: unterminated string; newline inserted
pstring.s:6: Warning: unterminated string; newline inserted
pstring.s:7: Warning: unterminated string; newline inserted
pstring.s:8: Warning: unterminated string; newline inserted
pstring.s:9: Warning: unterminated string; newline inserted
pstring.s:10: Warning: unterminated string; newline inserted
pstring.s:11: Warning: unterminated string; newline inserted
pstring.s:12: Warning: unterminated string; newline inserted
pstring.s:13: Warning: unterminated string; newline inserted
pstring.s:14: Warning: unterminated string; newline inserted
pstring.s:15: Warning: unterminated string; newline inserted
pstring.s:16: Warning: unterminated string; newline inserted
pstring.s:17: Warning: unterminated string; newline inserted
pstring.s:18: Warning: unterminated string; newline inserted
pstring.s:19: Warning: unterminated string; newline inserted
pstring.s:20: Warning: unterminated string; newline inserted
pstring.s:21: Warning: unterminated string; newline inserted
pstring.s:22: Warning: unterminated string; newline inserted
pstring.s:23: Warning: unterminated string; newline inserted
pstring.s:24: Warning: unterminated string; newline inserted
pstring.s:25: Warning: unterminated string; newline inserted
pstring.s:26: Warning: unterminated string; newline inserted
pstring.s:27: Warning: unterminated string; newline inserted
pstring.s:28: Warning: unterminated string; newline inserted
pstring.s:29: Warning: unterminated string; newline inserted
pstring.s:30: Warning: unterminated string; newline inserted
pstring.s:31: Warning: unterminated string; newline inserted
pstring.s:32: Warning: unterminated string; newline inserted
pstring.s:33: Warning: unterminated string; newline inserted
pstring.s:34: Warning: unterminated string; newline inserted
pstring.s:35: Warning: unterminated string; newline inserted
pstring.s:36: Warning: unterminated string; newline inserted
pstring.s:37: Warning: unterminated string; newline inserted
pstring.s:38: Warning: unterminated string; newline inserted
pstring.s:39: Warning: unterminated string; newline inserted
pstring.s:40: Warning: unterminated string; newline inserted
pstring.s:41: Warning: unterminated string; newline inserted
pstring.s:42: Warning: unterminated string; newline inserted
pstring.s:43: Warning: unterminated string; newline inserted
pstring.s:44: Warning: unterminated string; newline inserted
pstring.s:45: Warning: unterminated string; newline inserted
pstring.s:46: Warning: unterminated string; newline inserted
pstring.s:47: Warning: unterminated string; newline inserted
pstring.s:48: Warning: unterminated string; newline inserted
pstring.s:49: Warning: unterminated string; newline inserted
pstring.s:50: Warning: unterminated string; newline inserted
pstring.s:51: Warning: unterminated string; newline inserted
pstring.s:52: Warning: unterminated string; newline inserted
pstring.s:53: Warning: unterminated string; newline inserted
pstring.s:54: Warning: unterminated string; newline inserted
pstring.s:55: Warning: unterminated string; newline inserted
pstring.s:56: Warning: unterminated string; newline inserted
pstring.s:57: Warning: unterminated string; newline inserted
pstring.s:58: Warning: unterminated string; newline inserted
pstring.s:59: Warning: unterminated string; newline inserted
pstring.s:60: Warning: unterminated string; newline inserted
pstring.s:61: Warning: unterminated string; newline inserted
pstring.s:62: Warning: unterminated string; newline inserted
pstring.s:63: Warning: unterminated string; newline inserted
pstring.s:64: Warning: unterminated string; newline inserted
pstring.s:65: Warning: unterminated string; newline inserted
pstring.s:66: Warning: unterminated string; newline inserted
pstring.s:67: Warning: unterminated string; newline inserted
pstring.s:68: Warning: unterminated string; newline inserted
pstring.s:69: Warning: unterminated string; newline inserted
pstring.s:70: Warning: unterminated string; newline inserted
pstring.s:71: Warning: unterminated string; newline inserted
pstring.s:72: Warning: unterminated string; newline inserted
pstring.s:73: Warning: unterminated string; newline inserted
pstring.s:74: Warning: unterminated string; newline inserted
pstring.s:75: Warning: unterminated string; newline inserted
pstring.s:76: Warning: unterminated string; newline inserted
pstring.s:77: Warning: unterminated string; newline inserted
pstring.s:78: Warning: unterminated string; newline inserted
pstring.s:79: Warning: unterminated string; newline inserted
pstring.s:80: Warning: unterminated string; newline inserted
pstring.s:81: Warning: unterminated string; newline inserted
pstring.s:82: Warning: unterminated string; newline inserted
pstring.s:83: Warning: unterminated string; newline inserted
pstring.s:84: Warning: unterminated string; newline inserted
pstring.s:85: Warning: unterminated string; newline inserted
pstring.s:86: Warning: unterminated string; newline inserted
pstring.s:87: Warning: unterminated string; newline inserted
pstring.s:88: Warning: unterminated string; newline inserted
pstring.s:89: Warning: unterminated string; newline inserted
pstring.s:90: Warning: unterminated string; newline inserted
pstring.s:91: Warning: unterminated string; newline inserted
pstring.s:92: Warning: unterminated string; newline inserted
pstring.s:93: Warning: unterminated string; newline inserted
pstring.s:94: Warning: unterminated string; newline inserted
pstring.s:95: Warning: unterminated string; newline inserted
pstring.s:96: Warning: unterminated string; newline inserted
pstring.s:97: Warning: unterminated string; newline inserted
pstring.s:98: Warning: unterminated string; newline inserted
pstring.s:99: Warning: unterminated string; newline inserted
pstring.s:100: Warning: unterminated string; newline inserted
pstring.s:101: Warning: unterminated string; newline inserted
pstring.s:102: Warning: unterminated string; newline inserted
pstring.s:103: Warning: unterminated string; newline inserted
pstring.s:104: Warning: unterminated string; newline inserted
pstring.s:105: Warning: unterminated string; newline inserted
pstring.s:106: Warning: unterminated string; newline inserted
pstring.s:107: Warning: unterminated string; newline inserted
pstring.s:108: Warning: unterminated string; newline inserted
pstring.s:109: Warning: unterminated string; newline inserted
pstring.s:110: Warning: unterminated string; newline inserted
pstring.s:111: Warning: unterminated string; newline inserted
pstring.s:112: Warning: unterminated string; newline inserted
pstring.s:113: Warning: unterminated string; newline inserted
pstring.s:114: Warning: unterminated string; newline inserted
pstring.s:115: Warning: unterminated string; newline inserted
pstring.s:116: Warning: unterminated string; newline inserted
pstring.s:117: Warning: unterminated string; newline inserted
pstring.s:118: Warning: unterminated string; newline inserted
pstring.s:119: Warning: unterminated string; newline inserted
pstring.s:120: Warning: unterminated string; newline inserted
pstring.s:121: Warning: unterminated string; newline inserted
pstring.s:122: Warning: unterminated string; newline inserted
pstring.s:123: Warning: unterminated string; newline inserted
pstring.s:124: Warning: unterminated string; newline inserted
pstring.s:125: Warning: unterminated string; newline inserted
pstring.s:126: Warning: unterminated string; newline inserted
pstring.s:127: Warning: unterminated string; newline inserted
pstring.s:128: Warning: unterminated string; newline inserted
pstring.s:129: Warning: unterminated string; newline inserted
pstring.s:130: Warning: unterminated string; newline inserted
pstring.s:131: Warning: unterminated string; newline inserted
pstring.s:132: Warning: unterminated string; newline inserted
pstring.s:133: Warning: unterminated string; newline inserted
pstring.s:134: Warning: unterminated string; newline inserted
pstring.s:135: Warning: unterminated string; newline inserted
pstring.s:136: Warning: unterminated string; newline inserted
pstring.s:137: Warning: unterminated string; newline inserted
pstring.s:138: Warning: unterminated string; newline inserted
pstring.s:139: Warning: unterminated string; newline inserted
pstring.s:140: Warning: unterminated string; newline inserted
pstring.s:141: Warning: unterminated string; newline inserted
pstring.s:142: Warning: unterminated string; newline inserted
pstring.s:143: Warning: unterminated string; newline inserted
pstring.s:144: Warning: unterminated string; newline inserted
pstring.s:145: Warning: unterminated string; newline inserted
pstring.s:146: Warning: unterminated string; newline inserted
pstring.s:147: Warning: unterminated string; newline inserted
pstring.s:148: Warning: unterminated string; newline inserted
pstring.s:149: Warning: unterminated string; newline inserted
pstring.s:150: Warning: unterminated string; newline inserted
pstring.s:151: Warning: unterminated string; newline inserted
pstring.s:152: Warning: unterminated string; newline inserted
pstring.s:153: Warning: unterminated string; newline inserted
pstring.s:154: Warning: unterminated string; newline inserted
pstring.s:155: Warning: unterminated string; newline inserted
pstring.s:156: Warning: unterminated string; newline inserted
pstring.s:157: Warning: unterminated string; newline inserted
pstring.s:158: Warning: unterminated string; newline inserted
pstring.s:159: Warning: unterminated string; newline inserted
pstring.s:160: Warning: unterminated string; newline inserted
pstring.s:161: Warning: unterminated string; newline inserted
pstring.s:162: Warning: unterminated string; newline inserted
pstring.s:163: Warning: unterminated string; newline inserted
pstring.s:164: Warning: unterminated string; newline inserted
pstring.s:165: Warning: unterminated string; newline inserted
pstring.s:166: Warning: unterminated string; newline inserted
pstring.s:167: Warning: unterminated string; newline inserted
pstring.s:168: Warning: unterminated string; newline inserted
pstring.s:169: Warning: unterminated string; newline inserted
pstring.s:170: Warning: unterminated string; newline inserted
pstring.s:171: Warning: unterminated string; newline inserted
pstring.s:172: Warning: unterminated string; newline inserted
pstring.s:173: Warning: unterminated string; newline inserted
pstring.s:174: Warning: unterminated string; newline inserted
pstring.s:175: Warning: unterminated string; newline inserted
pstring.s:176: Warning: unterminated string; newline inserted
pstring.s:177: Warning: unterminated string; newline inserted
pstring.s:178: Warning: unterminated string; newline inserted
pstring.s:179: Warning: unterminated string; newline inserted
pstring.s:180: Warning: unterminated string; newline inserted
pstring.s:181: Warning: unterminated string; newline inserted
pstring.s:182: Warning: unterminated string; newline inserted
pstring.s:183: Warning: unterminated string; newline inserted
pstring.s:184: Warning: unterminated string; newline inserted
pstring.s:185: Warning: unterminated string; newline inserted
pstring.s:186: Warning: unterminated string; newline inserted
pstring.s:187: Warning: unterminated string; newline inserted
pstring.s:188: Warning: unterminated string; newline inserted
pstring.s:189: Warning: unterminated string; newline inserted
pstring.s:190: Warning: unterminated string; newline inserted
pstring.s:191: Warning: unterminated string; newline inserted
pstring.s:192: Warning: unterminated string; newline inserted
pstring.s:193: Warning: unterminated string; newline inserted
pstring.s:194: Warning: unterminated string; newline inserted
pstring.s:195: Warning: unterminated string; newline inserted
pstring.s:196: Warning: unterminated string; newline inserted
pstring.s:197: Warning: unterminated string; newline inserted
pstring.s:198: Warning: unterminated string; newline inserted
pstring.s:199: Warning: unterminated string; newline inserted
pstring.s:200: Warning: unterminated string; newline inserted
pstring.s:201: Warning: unterminated string; newline inserted
pstring.s:202: Warning: unterminated string; newline inserted
pstring.s:203: Warning: unterminated string; newline inserted
pstring.s:204: Warning: unterminated string; newline inserted
pstring.s:205: Warning: unterminated string; newline inserted
pstring.s:206: Warning: unterminated string; newline inserted
pstring.s:207: Warning: unterminated string; newline inserted
pstring.s:208: Warning: unterminated string; newline inserted
pstring.s:209: Warning: unterminated string; newline inserted
pstring.s:210: Warning: unterminated string; newline inserted
pstring.s:211: Warning: unterminated string; newline inserted
pstring.s:212: Warning: unterminated string; newline inserted
pstring.s:213: Warning: unterminated string; newline inserted
pstring.s:214: Warning: unterminated string; newline inserted
pstring.s:215: Warning: unterminated string; newline inserted
pstring.s:216: Warning: unterminated string; newline inserted
pstring.s:217: Warning: unterminated string; newline inserted
pstring.s:218: Warning: unterminated string; newline inserted
pstring.s:219: Warning: unterminated string; newline inserted
pstring.s:220: Warning: unterminated string; newline inserted
pstring.s:221: Warning: unterminated string; newline inserted
pstring.s:222: Warning: unterminated string; newline inserted
pstring.s:223: Warning: unterminated string; newline inserted
pstring.s:224: Warning: unterminated string; newline inserted
pstring.s:225: Warning: unterminated string; newline inserted
pstring.s:226: Warning: unterminated string; newline inserted
pstring.s:227: Warning: unterminated string; newline inserted
pstring.s:228: Warning: unterminated string; newline inserted
pstring.s:229: Warning: unterminated string; newline inserted
pstring.s:230: Warning: unterminated string; newline inserted
pstring.s:231: Warning: unterminated string; newline inserted
pstring.s:232: Warning: unterminated string; newline inserted
pstring.s:233: Warning: unterminated string; newline inserted
pstring.s:234: Warning: unterminated string; newline inserted
pstring.s:235: Warning: unterminated string; newline inserted
321123242尼古拉·巴金
.第节.罗达
错误:。字符串“无效输入!\n'#错误消息。
.文本
.global pstrlen#接收指向pstring的指针作为参数。
.type pstrlen,@function#以字节形式返回长度。
pstrlen:
按%ebp保存旧FP。
移动%esp,%ebp#设置新FP。
movl 8(%ebp),%eax#检索指向pstring的指针。
movb(%eax),%al#将参数的第一个字节复制到%al中
movzbl%al,%eax#零填充寄存器的其他3个字节。
movl%ebp,%esp#恢复旧堆栈指针-释放所有已用内存。
popl%ebp#还原旧帧指针(调用方函数帧)
ret#返回调用者函数
.global replaceChar#接收指向pstring的指针、oldChar字节和newChar字节作为参数。
.type replaceChar,@function#将所有旧字符替换为新字符,并返回指向pstring的指针
替换字符:
按%ebp#保存旧FP
移动%esp,%ebp#设置新FP
按下%ebx#在堆栈上保存%ebx
movl 8(%ebp),%eax#从堆栈中获取pstring指针。
movb(%eax),%bh#检索到pstring的len
addl$1,%eax#将指针对齐以指向字符串本身
movl 12(%ebp),%ecx#获取oldChar参数。
movb%cl,%dl#将oldChar存储在%dl中
movl16(%ebp),%ecx#获取newChar参数。
movb%cl,%dh#在%dh中存储新字符
movb$0,%bl#将计数寄存器初始化为1。
RCT测试:
cmpb%bh,%bl#试验
je rcDONE#如果测试:转到done
rcLOOP:#循环标签
cmpb%dl,(%eax)#将当前字节与oldChar字节进行比较
je rcCHANGE#跳转以更改旧字符。
rIncrement:#用于增加当前字符和计数变量的标签。
增加$1,%bl#增加计数
添加$1,%eax#将字符串指针增加一个字节。
jmp rcTEST#我们不希望无限循环导致分段错误,是吗?
更改:
movb%dh,(%eax)#用新字符覆盖旧字符
jmp rcINCREMENT#继续使用循环机制
完成:
mov 8(%ebp),%eax#将返回值设置为pstring指针。
popl%ebx#还原%ebx寄存器。
movl%ebp,%esp#恢复旧堆栈指针-释放所有已用内存。
popl%ebp#还原旧帧指针(调用方函数帧)
ret#返回调用者函数
.global pstrijcpy
.type pstrijcpy,@function
pstrijcpy:
按%ebp#保存旧FP
移动%esp,%ebp#设置新FP
#使用eax、ebx、ech、edx、,
将%ebx向后推%ebx向上。
movl 16(%ebp),%eax#带i的dword
移动%al,%bl#存储在%bl中的i
movl 20(%ebp),%eax#带j的dword
movb%al,%bh#将j存储在%bh中
movl 8(%ebp),%eax#将eax初始化为dst ptr。
movb(%eax),%dh#%dh:转到错误
cmpb%dh,%bl#i-dst.len
jg cpyERROR#if>:转到错误
cmp%dh,%bh#j-dst.len
jg cpyERROR#if>:转到错误
#现在我将向指向字符串的指针添加I。
向上推%edx#备份edx
movzbl%bl,%edx#显然我可以使用'movl%bl,%eax',所以我这样做了。
添加%edx,%eax#将dst提前到第i个字符
添加%edx,%ecx#将src提前到第i个字符
popl%edx#恢复edx
cpyTEST:
cmpb%bh,%bl#比较i和j
一旦i大于j,我们就完了。
cpyLOOP:
movb(%ecx),%dl#因为我已经检查了I和j错误在第3行,如消息所示。您有“string”
而不是“string”
。(请注意最后的报价)
此外,在cmpb
指令上的“Test”之类的注释也是无用的。您应该说明代码为什么会这样做,或者至少说明涉及哪些数据。我知道写评论很有诱惑力,读起来像insn ref手册,但不要
movb$0,%bl#将计数寄存器初始化为1。
特别有趣
此外,将代码缩进比标签多一个级别,这样它们就会突出
顺便说一句,维基上有很多很好的链接。感谢患者的回复。是的,这些评论并没有特别的启发-我的借口是我有更大的头痛要处理(有时是字面上的),我坚持这样做。计数寄存器一是坏的,虽然,可能仍然从一些变化或其他。总的来说,谢谢,一旦我能腾出一些时间,我会浏览一下维基。
321123242 Nikolay Babkin
.section .rodata
error: .string "invalid input!\n' # error message.
.text
.global pstrlen #receives a pointer to a pstring as argument.
.type pstrlen, @function #returns the length as a byte.
pstrlen:
pushl %ebp #save old FP.
movl %esp, %ebp #set new FP.
movl 8(%ebp), %eax #retrieve pointer to pstring.
movb (%eax), %al #copy the first byte of the argument into %al
movzbl %al, %eax #Zero-fill the other 3 bytes of the register.
movl %ebp, %esp #restore the old stack pointer - release all used memory.
popl %ebp #restore old frame pointer (the caller function frame)
ret #return to caller function
.global replaceChar #receives a pointer to a pstring, a oldChar byte and a newChar byte as arguments.
.type replaceChar, @function #replaces all oldChars with newChars and returns the pointer to the pstring
replaceChar:
pushl %ebp #save old FP
movl %esp, %ebp #set new FP
pushl %ebx #save %ebx on stack
movl 8(%ebp), %eax #get the pstring pointer from the stack.
movb (%eax), %bh #retrieved the len of the pstring
addl $1, %eax #align the pointer to point to the string itself
movl 12(%ebp), %ecx #get the oldChar argument.
movb %cl, %dl #store oldChar in %dl
movl 16(%ebp), %ecx #get the newChar argument.
movb %cl, %dh #store newChar in %dh
movb $0, %bl #initialize count register to 1.
rcTEST:
cmpb %bh, %bl #Test
je rcDONE #if Test: goto done
rcLOOP: #loop label
cmpb %dl, (%eax) #compare the current byte to the oldChar byte
je rcCHANGE #jump to change the oldChar.
rcINCREMENT: #label for incrementing the current char and the count variable.
add $1, %bl #increment the count
add $1, %eax #increment the string pointer one byte.
jmp rcTEST #Don't want no infinite loops causing segmentation faults, do we?
rcCHANGE:
movb %dh, (%eax) #overwrite the oldChar with a newChar
jmp rcINCREMENT #move on with the loop mechanism
rcDONE:
mov 8(%ebp), %eax #set return value to be the pstring pointer.
popl %ebx #restore %ebx register.
movl %ebp, %esp #restore the old stack pointer - release all used memory.
popl %ebp #restore old frame pointer (the caller function frame)
ret #return to caller function
.global pstrijcpy
.type pstrijcpy, @function
pstrijcpy:
pushl %ebp #save old FP
movl %esp, %ebp #set new FP
#using eax, ebx, ech, edx,
pushl %ebx #back %ebx up.
movl 16(%ebp), %eax #the dword with i
movb %al, %bl #store i in %bl
movl 20(%ebp), %eax #the dword with j
movb %al, %bh #store j in %bh
movl 8(%ebp), %eax #initialize eax to dst ptr.
movb (%eax), %dh #%dh <- dst.len
addl $1, %eax #advance %eax by one byte to the string
movl 12(%ebp), %ecx #initialize ecx to src ptr.
mov (%ecx), %dl #%dl <- src.len
addl $1, %ecx #advance %ecx by one byte to the string
cmpb %dl, %bl #i-src.len
jg cpyERROR #if >: goto error
cmp %dl, %bh #j-src.len
jg cpyERROR #if >: goto error
cmpb %dh, %bl #i-dst.len
jg cpyERROR #if >: goto error
cmp %dh, %bh #j-dst.len
jg cpyERROR #if >: goto error
#now I will add i to the pointers that point to the strings.
push %edx #back edx up
movzbl %bl, %edx #apparently I can use 'movl %bl, %eax', so I did this.
addl %edx, %eax #advance dst to ith character
addl %edx, %ecx #advance src to ith character
popl %edx #restore edx
cpyTEST:
cmpb %bh, %bl #compare i with j
jg cpyDONE #once i is greater than j, we are done.
cpyLOOP:
movb (%ecx), %dl #Since I already checked that i and j <= the lengths, I can use them
movb %dl, (%eax) #Move byte from src to dst.
addl $1, %ecx #Increment src to next byte
addl $1, %eax #Increment dst to next byte
addl $1, %ebx #Increment i by 1.
jmp cpyTEST #goto test
cpyERROR: #don't need to back registers up.
pushl $error #push the message to be printed.
call printf #use printf to print error message
cpyDONE:
popl %ebx #restore %ebx
movl 8(%ebp), %eax #set return value to be dst pointer.
movl %ebp, %esp #restore the old stack pointer - release all used memory.
popl %ebp #restore old frame pointer (the caller function frame)
ret #return to caller function
.global swapCase #swaps the cases of the string.
.type swapCase, @function
swapCase:
pushl %ebp #save old FP
movl %esp, %ebp #set new FP
movl 8(%ebp), %eax #get pointer to pstring
movb (%eax), %cl #get length of pstring
addl $1, %eax #move pointer to string itself
scLTEST: #loop condition.
cmpb $0, %cl #compare length with 0
je scDONE #if length is zero, goto done
jmp scLOOP #else: goto loop
scLOOP:
cmpb $97, (%eax) #compares first byte of string with 'a'.
jge scTRYLOWER #byte is lowercase-possible.
cmpb $90, (%eax) #compares first byte of string with 'Z'.
jle scTRYUPPER #byte is uppercase-possible.
jmp scINC #byte is between 65 and 97, so not a letter.
scTRYUPPER: #checking if byte is really upper-case.
cmpb $65, (%eax) #compare byte with 'A'.
jge scCHANGETOLOWER #if byte is 'A' or after, it is upper-case, so change to lower-case.
jmp scINC #otherwise, it is below 'A' and is thus not a letter.
scTRYLOWER:
cmpb $122, (%eax) #compare byte with 'z'.
jle scCHANGETOUPPER #if it is before or at 'z', it is a lower-case letter.
jmp scINC #otherwise, it is over 'z' and not a letter.
scCHANGETOUPPER:
subb $32, (%eax) #reduce the byte from range [97,122] to [65,90]
jmp scINC
scCHANGETOLOWER:
addb $32, (%eax) #increase the byte to range [97,122] from [65,90]
#jmp scINC #for now, the jump is not necessary since the increment stage is already after it.
scINC:
addl $1, %eax #increment %eax to next byte
decb %cl #decrement counter
jmp scLTEST #end current loop iteration
scDONE:
movl 8(%ebp), %eax #set return value to pointer to pstring.
movl %ebp, %esp #restore old stack pointer
popl %ebp #restore old FP
ret #return to caller function
.global pstrijcmp #compares pstring1 and pstring 2 in range i to j.
.type pstrijcmp, @function #returns -1 if pstring1 < pstring2, 0 if equal and 1 if greater. -2 is error value.
pstrijcmp:
pushl %ebp #save old FP
movl %esp, %ebp #set new FP
pushl %ebx #back %ebx up.
movl 16(%ebp), %eax #retrieve the dword with i.
movb %al, %ch #set %ch to be i.
movl 20(%ebp), %eax #retrieve the dword with j.
movb %al, %cl #set %cl to be j.
movl 8(%ebp), %eax #set pstring1ptr into eax.
movl 12(%ebp), %edx #set pstring2ptr into edx.
cmpb (%eax), %ch #i-str1.len
jg cmpERROR #if i>len: goto error
cmp (%eax), %cl #j-str1.len
jg cmpERROR #if jlen>: goto error
cmpb (%edx), %ch #i-str2.len
jg cmpERROR #if i>len2: goto error
cmp (%edx), %cl #j-str2.len
jg cmpERROR #if j>len2: goto error
incl %eax #increment eax to get past the length byte
incl %edx #increment edx to get past the length byte
cmpTEST:
cmpb %cl, %ch #compare i with j
jg cmpPREDONE #goto done once i>j
#jmp cmpLOOP #else: goto loop
cmpLOOP:
movb (%eax), %bl #take current str1 byte into %bl
cmpb %bl, (%edx) #compare %bl with first %edx byte
je cmpINC #if same: increment phase.
jl cmpLESS #str1 is before str2 lexicographically.
movl $1, %eax #set return value to 1.
jmp cmpDONE #done.
cmpLESS:
movl $-1, %eax #set return value to -1
jmp cmpDONE #done
cmpINC:
incl %eax #increment str1 pointer.
incl %edx #increment str2 pointer.
incb %ch #i++
jmp cmpTEST #current loop iteration is over.
cmpERROR: #don't need to back registers up.
pushl $error #push the message to be printed.
call printf #use printf to print error message
movl $-2, %eax #set return value to -2
jmp cmpDONE
cmpPREDONE:
movl $0, %eax #set return value to 0.
cmpDONE:
popl %ebx #restore old %ebx
movl %ebp, %esp #restore old stack pointer
popl %ebp #restore old FP
ret #return to caller function