DRF
User
 Platinum Osdever
| Posts: 123 |   | Karma: 1
|
Re: Printing strings - 2004/10/24 12:13
Ok, to optimise your existing code you can remove the text setup stuff so having the loop after the mov ah , bh and bl commands as long as you remember not to change those registers within the loop (otherwise your moving stuff to the registers each time you print a char that isn't needed but at this level it won't matter)
Also the jump command is probably what is causing the problem, the command I use is 'jz' Jump if Zero. So if you OR the values you should get: 0 OR 0 = 0 (anything else is 1) so the result is obviously if you pass a 0 into al, zero. I'm not sure (without having a reference manual to hand) how that OR instruction effects the equal flag to know if the je will work or not but logically the jz is a better choice I would suggest.
The procedure I came up with for string printing is: (pretty much cut and paste from one of my documents)
| Code: |
PutStr: ; Procedure label/start
; Set up the registers for the interrupt call
mov ah,0x0E ; The function to display a chacter (teletype)
mov bh,0x00 ; Page number
mov bl,0x07 ; Normal text attribute (White text black back ground, change value for random colours)
.nextchar ; Internal label (needed to loop round for the next character)
lodsb ; I think of this as LOaD String Block
; (Not sure if thats the real meaning though)
; Loads [SI] into AL and increases SI by one
; Check for end of string '0'
or al,al ; Sets the zero flag if al = 0
; (OR outputs 0's where there is a zero bit in the register)
jz .return ; If the zero flag has been set go to the end of the procedure.
; Zero flag gets set when an instruction returns 0 as the answer.
int 0x10 ; Run the BIOS video interrupt
jmp .nextchar ; Loop back round to the top
.return ; Label at the end to jump to when complete
ret ; Return to main program
|
(I apologise for the hard to read code above the forum seems to not like me using indentations on code)
This would be executed by the command:
| Code: |
mov si, stringname
call PutStr
|
Where stringname is:
| Code: |
stringname db "Test String",0
|
Hope that helps, feel free to try an other solution but my print string commands there if you can't find another way yourself. But I think by changing the je to jz you may solve the problem. (Other useful additions to printing is that you can make a string as: "String",13,10,0 and the 13,10 are the ascii codes to start a new line if you want to print more than 1 thing)
In direct response to your question it is possible to count the characters in a string but it will be harder and very similar method that you might as well put the extra few lines of code in to print to screen at the same time.
If that doesn't help please reply with a quote of the message displayed on the screen and the method you use to call the function.
Daniel
|