diff --git a/jumpforth.S b/jumpforth.S index f956aa7..5b0eb14 100644 --- a/jumpforth.S +++ b/jumpforth.S @@ -942,6 +942,30 @@ defcode CMOVE_UP,"CMOVE>" mov %edx,%esi NEXT +/* ( c-addr1 u1 c-addr2 u2 -- -1 | 0 | 1 ) Lexically compare two strings */ +defcode COMPARE + mov %esi,%edx + mov (%esp),%ecx + mov 8(%esp),%ebx + xor %eax,%eax + cmp %ebx,%ecx + jbe 1f + mov %ebx,%ecx +1: mov 12(%esp),%esi + mov 4(%esp),%edi + repe cmpsb + je 3f +2: seta %al + shl $1,%eax + dec %eax + jmp 4f +3: cmp (%esp),%ebx + jne 2b +4: add $16,%esp + push %eax + mov %edx,%esi + NEXT + /* ( a -- ) ( R: -- a ) */ defcode TOR,">R" pop %eax diff --git a/startup.4th b/startup.4th index deb7599..a537ff5 100644 --- a/startup.4th +++ b/startup.4th @@ -1067,16 +1067,6 @@ CREATE DISPLAY-ITEM-LIMIT 6 , : -TRAILING ( c-addr u1 -- c-addr u2 ) BEGIN DUP AND-THEN 2DUP 1- + C@ SPACE? THEN WHILE 1- REPEAT ; -\ Return -1, 0, or 1 if the left string is respectively -\ less than, equal to, or greater than the right string -: COMPARE ( c-addr1 u1 c-addr2 u2 -- -1 | 0 | 1 ) - ROT SWAP ▪ 2DUP U<=> -ROT 2>R -ROT 2R> ▪ UMIN 0 ?DO - ( S: u1-u2 c-addr1 c-addr2 R: loop-sys ) - OVER I + C@ OVER I + C@ - ( S: u1-u2 c-addr1 c-addr2 ch1 ch2 ) - U<=> ?DUP IF -ROT 2>R NIP 2R> LEAVE THEN - LOOP ▪ 2DROP ; - \ Convert a character to lowercase or uppercase, respectively : TO-LOWER ( ch1 -- ch2 ) DUP [[ CHAR A ]] [[ CHAR Z 1+ ]] WITHIN IF [[ CHAR a CHAR A - ]] + THEN ;