Binary strings: Difference between revisions
Content added Content deleted
(→{{header|BQN}}: Clarify in what sense BQN has byte strings) |
Puppydrum64 (talk | contribs) |
||
Line 30: | Line 30: | ||
97 |
97 |
||
</pre> |
</pre> |
||
=={{header|8086 Assembly}}== |
|||
The 8086 has built-in support for handling byte and word strings, using <code>DS:SI</code> and <code>ES:DI</code> as the source and destination pointers, respectively. String functions can either auto-increment or auto-decrement the pointers held in these registers; the '''direction flag''' determines which one takes place. (<code>CLD</code> for auto-inc, <code>STD</code> for auto-dec.) |
|||
===Copying strings=== |
|||
<lang asm>;this code assumes that both DS and ES point to the correct segments. |
|||
cld |
|||
mov si,offset TestMessage |
|||
mov di,offset EmptyRam |
|||
mov cx,5 ;length of the source string, you'll need to either know this |
|||
;ahead of time or calculate it. |
|||
rep movsb |
|||
ret |
|||
;there is no buffer overflow protection built into these functions so |
|||
;be careful!!! |
|||
TestMessage byte "Hello" |
|||
EmptyRam byte 0,0,0,0,0</lang> |
|||
===Checking if a particular byte exists=== |
|||
<lang asm>;this code assumes that ES points to the correct segment. |
|||
cld |
|||
mov di,offset TestMessage |
|||
mov al,'o' ;the byte we wish to check |
|||
mov cx,5 ;len(Test) |
|||
repnz scasb ;scan through the string and stop if a match is found. |
|||
;flags will be set accordingly |
|||
ret |
|||
TestMessage byte "Hello"</lang> |
|||
===Compare two strings=== |
|||
<lang asm>;this code assumes that both DS and ES point to the correct segments. |
|||
cld |
|||
mov si,offset foo |
|||
mov di,offset bar |
|||
mov cx,4 ;length of the shorter of the two. |
|||
repz cmpsb ;this will continue until the strings are different or CX = 0, whichever occurs first. If, after this, the zero flag is set and CX=0, the strings were the same. |
|||
ret |
|||
foo byte "test" |
|||
bar byte "test"</lang> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |