Jump to content
GDMike

Assembly code samples

Recommended Posts

Posted (edited)

Looky at my asterisk, sitting on top of!

For the life of me I don't know why automation code didn't work for me 

This took me 5 minutes maybe 10 I don't know I'm that messed up I guess..

Uh oh...I just found the word FOUND when looking for FIND.

 

IMG_20200716_171619679.jpg

Edited by GDMike

Share this post


Link to post
Share on other sites

It's always fun to find, but I found "FOUND" when looking for "FIND"

I'll look at the code, too just to see if it's something I did

IMG_20200716_172528107_HDR.jpg

Share this post


Link to post
Share on other sites
Posted (edited)

I don't think it's me, seems to tend to follow through on first letter found, then gives up. 

More pictures here

looking for orange on example picture 2., Not found

IMG_20200716_172836856.jpg

IMG_20200716_172948968.jpg

Edited by GDMike

Share this post


Link to post
Share on other sites

Maybe after finding the first character, but not the second, the length of search word needs to be reinstated?

Share this post


Link to post
Share on other sites
44 minutes ago, GDMike said:

Maybe after finding the first character, but not the second, the length of search word needs to be reinstated?

 

If you look at my code, you will see that the search string parameters are always reset after a partial match failure by JuMPing to SEARCH.

 

If your question has to do with my last comment, I was talking about  where to restart the search in the buffer not the search string (always reset).

 

...lee

  • Like 1

Share this post


Link to post
Share on other sites
33 minutes ago, Lee Stewart said:

 

If you look at my code, you will see that the search string parameters are always reset after a partial match failure by JuMPing to SEARCH.

 

If your question has to do with my last comment, I was talking about  where to restart the search in the buffer not the search string (always reset).

 

...lee

Now, only if the search string function was case insensitive...……………………...

 

 

Share this post


Link to post
Share on other sites
Posted (edited)
1 hour ago, Lee Stewart said:

 

If you look at my code, you will see that the search string parameters are always reset after a partial match failure by JuMPing to SEARCH.

 

If your question has to do with my last comment, I was talking about  where to restart the search in the buffer not the search string (always reset).

 

...lee

 

Your code worked for me!:)...

 

SEARCH MOV  R2,R4          ; copy search string address
       MOV  R3,R5          ; copy search string size
       INC  R1             ; adjust range for next instruction
SLOOP  DEC  R1             ; decrement search range
       JEQ  SNFND          ; to SNFND if out of range
       CB   *R4,*R0+       ; first char of search string found?
       JNE  SLOOP          ; if not, check next char
       INC  R4             ; if so, set to second search char
SLOOP1 DEC  R5             ; decrement search char count
       JEQ  SFOUND         ; if done, string is found!
       DEC  R1             ; decrement search range
       JEQ  SNFND          ; to SNFND if out of range
       CB   *R4+,*R0+      ; next char found?
       JEQ  SLOOP1         ; if so, check next char
       DEC  R0             ; if not, correct buffer address
       JMP  SEARCH         ; reset search string parameters
SNFND  CLR  R0             ; string not found in range
       RT                  ; return with R0 = 0
SFOUND S    R3,R0          ; we found it! correct address
       RT                  ; return with address of found string
 
       AORG >FE00
QUERI  TEXT 'FIND'
 
       AORG >C016
       TEXT 'GTRFOUNDDTH21HFFINDTEHDR'
 
       DEF  START
       REF  VMBW
BUFF   TEXT 'HAHA!'
START  LI   R0,>C000
       LI   R1,>1000
       LI   R2,QUERI
       LI   R3,4
       BL   @SEARCH
       CI   R0,>0
       JEQ  NOTFND
FOUND  MOV  R0,R1
       CLR  R0
       MOV  R3,R2
       BLWP @VMBW
       JMP  WAIT
NOTFND CLR  R0
       LI   R1,BUFF
       LI   R2,5
       BLWP @VMBW
WAIT   JMP  WAIT
       END

FOUND was ignored, in favor of FIND.:party:

leehaoi.thumb.JPG.3c759f6aa89c646caf1e80963e1d1a07.JPG

Edited by HOME AUTOMATION
Punct., improved example, somewhat.
  • Like 1

Share this post


Link to post
Share on other sites
25 minutes ago, BeeryMiller said:

Now, only if the search string function was case insensitive...……………………...

 

That should not be too difficult. I will work on it.

 

...lee

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

I'll try again

I'm always a day late and a dollar short!

I misplaced a jump to search and that was my problem.

Sorry, bout that.  it must of been a busy day yesterday with the construction out front tearing into the yard. But, I'm on track. I'm all good, except for the upper lowercase mix results.

I'll continue with inverting colors of word found routine, and replace, continue and stop options...

Thanks so much. 

This is beautiful 

Edited by GDMike

Share this post


Link to post
Share on other sites
Posted (edited)

If you are thinking about case insensitive searches, then remember that the difference between 'A' and 'a' is just one bit. 0100 0001 vs. 0110 0001.

* Assuming R0 is buffer pointer and R2 is search string pointer, which already is in upper case

	LI	R5,>2000

	MOVB	*R0+,R4
	SZCB	R5,R4
	CB	R4,*R2+	* Now you've compared the byte at *R2 with the byte at *R0, where the latter gives the same result, upper or lower case

Note that this approach also gives the same result for <CR> and '-', for example. But it's a fast method. Before you start, you should convert the whole search string to upper case, so you don't spend time doing that for each search position.

Edited by apersson850
Corrected a program error
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)

The strings in my program could consist of mixed sets, lower upper but I also have inverted characters, these are 123 bytes down the character set that are color inverted, i.e.,A=65, inverted A is character 65+123

Small a, same thing, character a+123 for the inverted color.

 

 

 

Edited by GDMike

Share this post


Link to post
Share on other sites
4 hours ago, apersson850 said:

If you are thinking about case insensitive searches, then remember that the difference between 'A' and 'a' is just one bit. 0100 0001 vs. 0110 0001.

* Assuming R0 is buffer pointer and R2 is search string pointer, which already is in upper case

	LI	R5,>30

	MOVB	*R0+,R4
	SZCB	R5,R4
	CB	R4,*R2+	* Now you've compared the byte at *R2 with the byte at *R0, where the latter gives the same result, upper or lower case

Note that this approach also gives the same result for <CR> and '-', for example. But it's a fast method. Before you start, you should convert the whole search string to upper case, so you don't spend time doing that for each search position.

Shouldn't that be a LI    R5,>20  ?????

 

Beery

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, BeeryMiller said:

Shouldn't that be a LI    R5,>20  ?????

 

Beery

 

Yes—but it should be in the MSB, so 

       LI   R5,>2000

 

...lee

  • Like 1

Share this post


Link to post
Share on other sites
7 hours ago, apersson850 said:

If you are thinking about case insensitive searches, then remember that the difference between 'A' and 'a' is just one bit. 0100 0001 vs. 0110 0001.

* Assuming R0 is buffer pointer and R2 is search string pointer, which already is in upper case

	LI	R5,>30

	MOVB	*R0+,R4
	SZCB	R5,R4
	CB	R4,*R2+	* Now you've compared the byte at *R2 with the byte at *R0, where the latter gives the same result, upper or lower case

Note that this approach also gives the same result for <CR> and '-', for example. But it's a fast method. Before you start, you should convert the whole search string to upper case, so you don't spend time doing that for each search position.

 

There are actually more characters than <CR> and ‘-’ that would be confused as well as not being able to distinguish <space> from <null> ( 0 ). It would be better (and, admittedly, slower) to convert only ‘a’ – ‘z’ to uppercase during comparison. The search string (as @apersson850 pointed out) should be converted to uppercase once at the beginning of a case-insensitive search routine, but, the conversion of only ‘a’ – ‘z’ will take more time because of the need to test for the lowercase range for each character in the search buffer.

 

...lee

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

I think ...it's ALIVE!:-o

       AORG >FE00
QUERI  TEXT 'COMEFINDMEBRO'
       DATA 0
 
       AORG >A000
SAVRT  DATA 0
VALID  DATA 0
SEARCH MOV  R11,@SAVRT
       LI   R12,>4100
       LI   R13,>5A00
       LI   R14,>6100
       LI   R15,>7A00
       LI   R3,QUERI
       MOV  R4,R7
CMPARE CB   *R3,*R4+
       JEQ  NEXT
       C    R4,R6
       JNE  CMPARE
       BL   @CASE
       JEQ  NEXT
OUTNO  JMP  BYE
NEXT   MOV  R4,R5
CONT   CB   *R3,@VALID
       JEQ  OUTYES
       C    R4,R6
       JEQ  OUTNO
       INC  R3
       CB   *R3,*R4+
       JEQ  CONT
       BL   @CASE
       JEQ  CONT
       C    R4,R6
       JEQ  OUTNO
RESTAR MOV  R5,R4
       JMP  SEARCH
OUTYES MOV  R5,R4
       DEC  R4
BYE    MOV  @SAVRT,R11
       RT
 
CASE   CB   *R3,R12
       JLT  OUT
       CB   *R3,R13
       JGT  HIVAL
       MOVB *R3,R8
       AI   R8,>2000
       JMP  SCAN1B
HIVAL  CB   *R3,R14
       JLT  OUT
       CB   *R3,R15
       JGT  OUT
       MOVB *R3,R8
       AI   R8,->2000
SCAN1B MOV  R7,R4
SCANB  CB   R4,R6
       JEQ  OUT
       CB   R8,*R4+
       JNE  SCANB
OUT    RT
 
       AORG >B008
TEST   TEXT 'COMEFINDMEBRO'
 
       AORG >AA00
       DEF  START
       REF  VMBW
BUFF   TEXT 'HAHA...'
START  LI   R4,>B000
       LI   R6,>C000
       BL   @SEARCH
       C    R4,R6
       JEQ  NOTFND
FOUND  CLR  R0
       MOV  R4,R1
       LI   R2,30
       BLWP @VMBW
       JMP  WAIT
NOTFND CLR  R0
       LI   R1,BUFF
       LI   R2,30
       BLWP @VMBW
WAIT   JMP  WAIT
       END

 

...Although, I could have had a V8 ...and some :sleep:.

 

:)

 

     Edit:

 

Turns out... When two of the same characters in the document, with cases different from the search string are parsed...

 

I can't come up with a short paragraph to describe what's wrong with the above code.
But if you use it ...You'll be SORRY!

Edited by HOME AUTOMATION
  • Like 1
  • Haha 1

Share this post


Link to post
Share on other sites
9 hours ago, Lee Stewart said:

 

There are actually more characters than <CR> and ‘-’ that would be confused as well as not being able to distinguish <space> from <null> ( 0 ). It would be better (and, admittedly, slower) to convert only ‘a’ – ‘z’ to uppercase during comparison. The search string (as @apersson850 pointed out) should be converted to uppercase once at the beginning of a case-insensitive search routine, but, the conversion of only ‘a’ – ‘z’ will take more time because of the need to test for the lowercase range for each character in the search buffer.

Yes, there are. I took carriage return as an example, since it's one of the more probable ones to find in a general set of strings. As a line separator, I mean. If the strings are stored with a length byte instead, then any code is possible.

If you use an inverted character set, then you should definitely space that an even (binary) number apart from the non-inverted characters. Preferably so that you can only set or clear bits to change from inverted to non-inverted. So a spacing of 128 works fine, for example. If you need to set one and clear another bit to make the switch, it takes longer time. The TMS 9900 provides SOC, SOCB, SZC and SZCB, which can be used to set or clear bits. Provided you use the correct bit mask, ehrm.... 🙃 Thanks for pointing that out! 😊

But the XOR instruction in the 9900 is 16 bit only, and the destination has to be a register.

 

Provided the spacing between inverted and non-inverted is 128, you can go from one version to the other, for a string in memory, like this

* Make them normal
	LI	R0,STRPNT
	LI	R1,STRLEN
	LI	R2,>8000
LOOP	SZCB	R2,*R0+
	DEC	R1
	JNE	LOOP

* Make them inverted
	LI	R0,STRPNT
	LI	R1,STRLEN
	LI	R2,>8000
LOOP	SOCB	R2,*R0+
	DEC	R1
	JNE	LOOP

 

  • Like 3

Share this post


Link to post
Share on other sites

I haven't test this but I think you could make a toggle function like this.

* TOGGLE higlight/normal
    LI  R0,STRPNT
    LI  R1,STRLEN
    LI  R2,>8000
LOOP    XOR R2,*R0+
        DEC R1
        JNE LOOP
 

 

  • Like 1

Share this post


Link to post
Share on other sites

I got lost way back..I'll just wait for my mind to catch up. I'm in a loop from there to here. Bwhahaha

I can easily convert a-z to uppercase,

I was also thinking about this. 

Make a copy of the screen, convert to uppercase, test the search, lock my cursor position, put my screen back to normal, place my cursor (invert my word for highlight)

 

Share this post


Link to post
Share on other sites
Posted (edited)
On 7/18/2020 at 4:01 AM, HOME AUTOMATION said:

...Although, I could have had a V8 ...and some :sleep:.

 

My code, works with random CaSeS, in both, search and searched terms.

:grin:
 

 

     Edit: Now, if only it worked right!:roll:

Edited by HOME AUTOMATION
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)

I haven't had success with the earlier one. 

I'll save Lee's version, and push yours into where I had Lee's.

Is your version asking for the same parameters as Lee's? R0,R1,R2,R3

And your moving what you neeed from those? If not, I'll have to find out where and how to get my Params to where you need them.

I'm only Searching 860 bytes at a given address.  

Can you make it like Lee's, just take my 3 values, length of search word, starting address, buffer length and returning me an address or zero?

I must add this: I think this comes from thinking forth, Lee sets up the argument needs quite well, asking for parameters to be passed to his routines. I admire this thinking.

 

 

Edited by GDMike

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...