ô >stringprnt ô -ô String passing (via CALL) demonstration (ô 2ô By Richard Murray <9ô Downloaded from http://www.heyrick.co.uk/assembler/ Fô P Z-codesize% = 180 : ô The code is 180 bytes dÞ code% codesize% nòbuild_code x ‚*è "Please enter some text: "my_string$ Œ –ñ '"Entering assembler..."  Ö print_string, my_string$ ª#ñ "...returned from assembler"' ´ ¾à È Ò: Ü æÝòbuild_code ð ã loop% = 8 ¸ 10 ˆ 2 ú P% = code%  L% = code% + codesize%  [ OPT loop%  "9 \ Note... This is coded for CLARITY, not speed! , 6 .print_string @E CMP R10, #1 ; Check one parameter was given J! BNE wrong_parameters T ^4 LDR R0, [R9] ; Load pointer h1 LDR R1, [R9, #4] ; Load type r |7 CMP R1, #&80 ; Is it a string? † BNE wrong_var_type  šE \ Word giving string pointer may not be word aligned, so we ¤B \ cannot use an LDR as results for non-aligned addresses ® \ are unpredictable... ¸ LDRB R1, [R0], #1  LDRB R2, [R0], #1 Ì" ADD R1, R1, R2, LSL#8 Ö LDRB R2, [R0], #1 à# ADD R1, R1, R2, LSL#16 ê LDRB R2, [R0], #1 ô# ADD R1, R1, R2, LSL#24 þ . LDRB R2, [R0], #4 ; Length  4 CMP R2, #0 ; Check length & BEQ exit 0 :> \ Now, R1 is string pointer and R2 is string length. D .loop N LDRB R0, [R1], #1 X SWI "OS_WriteC" b@ SUBS R2, R2, #1 ; SUBS sets Z bit when = 0 l BNE loop v € .exit ŠM SWI "OS_NewLine" ; So a blank string prints just that... ” MOV PC, R14 ž ¨ .wrong_parameters ² SWI "OS_WriteS" ¼4 EQUS "Incorrect number of parameters"+½0 Æ ALIGN Ð B passed_to_call Ú ä .wrong_var_type î SWI "OS_WriteS" ø) EQUS "Wrong variable type"+½0  ALIGN  H ; B passed_to_call ; Not required, will fall through    .passed_to_call *) \ rudimentary optimisation! 4 SWI "OS_WriteS" >- EQUS " passed to call"+½13+½10+½0 H ALIGN R MOV PC, R14 \ ] f í pá z ÿ