110 likes | 279 Views
Assembly. Session 10 string manipulations. MOVING Strings. Determine Current Location Determine New Location Determine number of bytes to transport TRANSPORT. START. Flow. init current + future pointers. Read Current Write Future. char was a $.
E N D
Assembly Session 10 string manipulations
MOVING Strings • Determine Current Location • Determine New Location • Determine number of bytes to transport • TRANSPORT
START Flow init current + future pointers Read Current Write Future char was a $ increase both currentand future pointers by 1 YES NO STOP
Code PROG EQU 0100h FROM EQU 0020h TO EQU 8000h EOT EQU 0024h ;---------------------------------------------------------- ORG 0000h jp PROG ; ;---------------------------------------------------------- ORG FROM DB "Inholland Is Great!!$" ;---------------------------------------------------------- ORG PROG ; This routine moves a string to ; another location and ends with a stop ; when a $ is reached ; ld BC,FROM ld HL,TO loop: ld a,(BC) ld (hl),a inc BC inc HL ; cp EOT jp nz,loop ; ; endmov: halt
String reverse diverse methods: • using pointers • move one forward, the other backwards • using stack • stack is first in, last-out
principle H E L L H E L L L L E H O O O PUSH POP
Flow START stack the string unstack the string STOP
Stack stack the string point at stringmake a token Read pointed characterstack character and eventual token char was end of string? increase pointer NO YES
Unstack unstackthe string point at destination POP a characterand store it at destination Token? increase pointer NO YES
BUBBLESORT H E L L O E H L L O E H L L O E H L L O E H L L O
BUBBLESORT 2 E H L L O E H L L O E H L L O E H L L O E H L L O