📄 vaxstring.s
字号:
# # strings are identical # # n <- 0 # z <- 1 # (byte in s1) eql (byte in s2) # v <- 0 # c <- 0 # # strings do not match # # n <- (byte in s1) lss (byte in s2) # z <- 0 # (byte in s1) neq (byte in s2) # v <- 0 # c <- (byte in s1) lssu (byte in s2) # # where "byte in s1" or "byte in s2" may indicate the fill character # # side effects: # # this routine uses one longword of stack. #- .globl vax$cmpc3vax$cmpc3: movzwl r0,r0 # clear unused bits & check for zero beql 2f # simply return if zero length string pushl r10 # save r10 so it can hold handler # establish_handler string_accvio movab string_accvio,r10 # MARK_POINT CMPC3_1 .text 2 .set table_size, table_size + 1 .word Lcmpc3_1 - module_base .text 3 .word cmpc3_1 - module_base .textLcmpc3_1:1: cmpb (r3)+,(r1)+ # character match? bneq 3f # exit loop if different sobgtr r0,1b # exit path for strings identical (r0 = 0, either on input or after loop) movl (sp)+,r10 # restore saved r102: clrl r2 # set r2 for output value of 0 tstl r0 # set condition codes rsb # return point for identical strings # exit path when strings do not match3: movl (sp)+,r10 # restore saved r10 movl r0,r2 # r0 and r2 are the same on exit cmpb -(r1),-(r3) # reset r1 and r3 and set condition codes rsb # return point when strings do not match #+ # functional description: # # the bytes of the string 1 specified by the length 1 and address 1 # operands are compared with the bytes of the string 2 specified by the # length 2 and address 2 operands. if one string is longer than the # other, the shorter string is conceptually extended to the length of the # longer by appending (at higher addresses) bytes equal to the fill # operand. comparison proceeds until inequality is detected or all the # bytes of the strings have been examined. condition codes are affected # by the result of the last byte comparison. two zero length strings # compare equal (i.e. z is set and n, v, and c are cleared). # # input parameters: # # r0<15:0> = len length of first character string (called s1) # r0<23:16> = fill fill character that is used when strings have # different lengths # r1 = addr address of first character string # r2<15:0> = len length of second character string (called s2) # r3 = addr address of second character string # # intermediate state: # # 31 23 15 07 00 # +----------------+----------------+----------------+----------------+ # | delta-pc | fill | src1len | : r0 # +----------------+----------------+----------------+----------------+ # | src1addr | : r1 # +----------------+----------------+----------------+----------------+ # | xxxxx | src2len | : r2 # +----------------+----------------+----------------+----------------+ # | src2addr | : r3 # +----------------+----------------+----------------+----------------+ # # output parameters: # # strings are identical # # r0 = 0 # r1 = address of one byte beyond end of s1 # r2 = 0 (same as r0) # r1 = address of one byte beyond end of s2 # # strings do not match # # r0 = number of bytes remaining in s1 when mismatch detected # (or zero if s1 exhausted before mismatch detected) # r1 = address of nonmatching byte in s1 # r2 = number of bytes remaining in s2 when mismatch detected # (or zero if s2 exhausted before mismatch detected) # r3 = address of nonmatching byte in s2 # # condition codes: # # in general, the condition codes reflect whether or not the strings # are considered the same or different. in the case of different # strings, the condition codes reflect the result of the comparison # that indicated that the strings are not equal. # # strings are identical # # n <- 0 # z <- 1 # (byte in s1) eql (byte in s2) # v <- 0 # c <- 0 # # strings do not match # # n <- (byte in s1) lss (byte in s2) # z <- 0 # (byte in s1) neq (byte in s2) # v <- 0 # c <- (byte in s1) lssu (byte in s2) # # where "byte in s1" or "byte in s2" may indicate the fill character # # side effects: # # this routine uses two longwords of stack. #- .globl vax$cmpc5vax$cmpc5: pushl r10 # save r10 so it can hold handler # establish_handler string_accvio movab string_accvio,r10 pushl r4 # save register ashl $-16,r0,r4 # get escape character movzwl r0,r0 # clear unused bits & is s1 length zero? beql L250 # branch if yes movzwl r2,r2 # clear unused bits & is s2 length zero? beql L230 # main loop. the following loop executes when both strings have characters # remaining and inequality has not yet been detected. # the following loop is a target for further optimization in that the # loop should not require two sobgtr instructions. note, though, that # the current unoptimized loop is easier to back up. # MARK_POINT CMPC5_1 .text 2 .set table_size, table_size + 1 .word Lcmpc5_1 - module_base .text 3 .word cmpc5_1 - module_base .textLcmpc5_1:L210: cmpb (r1)+,(r3)+ # characters match? bneq L280 # exit loop if bytes different sobgtr r0,L220 # check for s1 exhausted # the next test determines whether s2 is also exhausted. decl r2 # put r2 in step with r0 bneq L260 # branch if bytes remaining in s2 # this is the exit path for identical strings. if we get here, then both # r0 and r2 are zero. the condition codes are correctly set (by the ashl # instruction) so that registers are restored with a popr to aviod changing # the condition codes.identical: # popr $^m<r4,r10> # restore saved registers popr $0x410 rsb # exit indicating identical stringsL220: sobgtr r2,L210 # check for s2 exhausted # the following loop is entered when all of s2 has been processed but # there are characters remaining in s1. in other words, # # r0 gtru 0 # r2 eql 0 # # the remaining characters in s1 are compared to the fill character. # MARK_POINT CMPC5_2 .text 2 .set table_size, table_size + 1 .word Lcmpc5_2 - module_base .text 3 .word cmpc5_2 - module_base .textLcmpc5_2:L230: cmpb (r1)+,r4 # characters match? bneq L240 # exit loop if no match sobgtr r0,L230 # any more bytes in s1? brb identical # exit indicating identical stringsL240: cmpb -(r1),r4 # reset r1 and set condition codes brb no_match # exit indicating strings do not match # the following code executes if s1 has zero length on input. if s2 also # has zero length, the routine smply returns, indicating equal strings.L250: movzwl r2,r2 # clear unused bits. is s2 len also zero? beql identical # exit indicating identical strings # the following loop is entered when all of s1 has been processed but # there are characters remaining in s2. in other words, # # r0 eql 0 # r2 gtru 0 # # the remaining characters in s2 are compared to the fill character. # MARK_POINT CMPC5_3 .text 2 .set table_size, table_size + 1 .word Lcmpc5_3 - module_base .text 3 .word cmpc5_3 - module_base .textLcmpc5_3:L260: cmpb r4,(r3)+ # characters match? bneq L270 # exit loop if no match sobgtr r2,L260 # any more bytes in s2? brb identical # exit indicating identical stringsL270: cmpb r4,-(r3) # reset r3 and set condition codes brb no_match # exit indicating strings do not match # the following exit path is taken if both strings have characters # remaining and a character pair that did not match was detected.L280: cmpb -(r1),-(r3) # reset r1 and r3 and set condition codesno_match: # restore r4 and r10 # popr $^m<r4,r10> # without changing condition codes popr $0x410 rsb # exit indicating strings do not match #+ # functional description: # # the bytes of the string specified by the length and address operands are # successively used to index into a 256 byte table whose zeroth entry # address is specified by the table address operand. the byte selected # from the table is anded with the mask operand. the operation continues # until the result of the and is non-zero or all the bytes of the string # have been exhausted. if a non-zero and result is detected, the # condition code z-bit is cleared# otherwise, the z-bit is set. # # input parameters: # # r0<15:0> = len length of character string # r1 = addr address of character string # r2<7:0> = mask mask that is anded with successive characters # r3 = tbladdr address of 256-byte table # # intermediate state: # # 31 23 15 07 00 # +----------------+----------------+----------------+----------------+ # | delta-pc | xxxx | len | : r0 # +----------------+----------------+----------------+----------------+ # | addr | : r1 # +----------------+----------------+----------------+----------------+ # | xxxxx | xxxx | mask | : r2 # +----------------+----------------+----------------+----------------+ # | tbladdr | : r3 # +----------------+----------------+----------------+----------------+ # # output parameters: # # nonzero and result # # r0 = number of bytes remaining in the string (including the byte # that produced the nonzero and result) # r1 = address of the byte that produced the nonzero and result # r2 = 0 # r3 = tbladdr address of 256-byte table # # and result always zero (string exhausted) # # r0 = 0 # r1 = address of one byte beyond end of string # r2 = 0 # r3 = tbladdr address of 256-byte table # # condition codes: # # n <- 0 # z <- r0 eql 0 # v <- 0 # c <- 0 # # the z bit is clear if there was a nonzero and result. # the z bit is set if the input string is exhausted. # # side effects: # # this routine uses two longwords of stack. #- .globl vax$scancvax$scanc: movzwl r0,r0 # zero length string? beql 3f # simply return if yes pushl r10 # save r10 so it can hold handler # establish_handler string_accvio movab string_accvio,r10 pushl r4 # we need a scratch register1: movzbl (r1)+,r4 # get next character in string bitb r2,(r3)[r4] # index into table and and with mask bneq 4f # exit loop if nonzero sobgtr r0,1b # if we drop through the end of the loop into the following code, then # the input string was exhausted with no nonzero result.2: # popr $^m<r4,r10> # restore saved registers popr $0x4103: clrl r2 # set r2 for output value of 0 tstl r0 # set condition codes rsb # return # exit path from loop if and produced nonzero result4: decl r1 # point r1 to located character brb 2b # merge with common exit #+ # functional description: # # the bytes of the string specified by the length and address operands are # successively used to index into a 256 byte table whose zeroth entry # address is specified by the table address operand. the byte selected # from the table is anded with the mask operand. the operation continues # until the result of the and is zero or all the bytes of the string have # been exhausted. if a zero and result is detected, the condition code # z-bit is cleared# otherwise, the z-bit is set. # # input parameters: # # r0<15:0> = len length of character string # r1 = addr address of character string # r2<7:0> = mask mask that is anded with successive characters # r3 = tbladdr address of 256-byte table # # intermediate state: # # 31 23 15 07 00 # +----------------+----------------+----------------+----------------+ # | delta-pc | xxxx | len | : r0 # +----------------+----------------+----------------+----------------+ # | addr | : r1 # +----------------+----------------+----------------+----------------+ # | xxxxx | xxxx | mask | : r2 # +----------------+----------------+----------------+----------------+ # | tbladdr | : r3 # +----------------+----------------+----------------+----------------+ # # output parameters: # # zero and result #
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -