sgbrt
asked on
accessing character in Assembly language
I WAS WRITING A PROGRAM TO THAT PRINTS "HELLO WORLD" LIKE THIS:
H
E
L
L
O
W
O
R
L
D
THE PROGRAM THAT I WROTE GIVES ME THIS RESULT:
HELLO WORLD
ELLO WORLD
LLO WORLD
LO WORLD
O WORLD
WORLD
WORLD
ORLD
RLD
LD
D
WHAT AM I DOING WRONG? THE PROGRAM IS BELOW:
i
include irvine32.inc
.data
hello byte "HELLO WORLD",0 ; message to write
.code
main proc
call Clrscr
call Crlf
mov ebx, offset hello
call WriteChar
call Crlf
mov ebx, offset hello+1
call WriteChar
call Crlf
mov ebx, offset hello+2
call WriteChar
call Crlf
mov ebx, offset hello+3
call WriteChar
call Crlf
mov ebx, offset hello+4
call WriteChar
call Crlf
mov ebx, offset hello+5
call WriteChar
call Crlf
mov ebx, offset hello+6
call WriteChar
call Crlf
mov ebx, offset hello+7
call WriteChar
call Crlf
mov ebx, offset hello+8
call WriteChar
call Crlf
mov ebx, offset hello+9
call WriteChar
call Crlf
mov ebx, offset hello+10
call WriteChar
call Crlf
exit ; a macro that calls ExitProcess
main endp
end main
ASKER
I tried using WriteString, but didn't work!
You'll either have to extract the part of WriteChar that output's the character, or you could do something like this:
hello byte "H",13,10,"E",13,10,"L",13 ,10,"L",13 ,10,"O",13 ,10,0 ; message to write
.code
main proc
call Clrscr
call Crlf
mov ebx, offset hello
call WriteChar
exit ; a macro that calls ExitProcess
main endp
end main
hello byte "H",13,10,"E",13,10,"L",13
.code
main proc
call Clrscr
call Crlf
mov ebx, offset hello
call WriteChar
exit ; a macro that calls ExitProcess
main endp
end main
ASKER
LRHGuy, thanks but doesn't work!
So, what does it do?
Can you show me the WriteChar routine?
Can you show me the WriteChar routine?
Could WriteChar have a parameter of how many chars? Perhaps:
mov eax,w
before each call would help. Without 'WriteChar' we cannot help further.
Paul
mov eax,w
before each call would help. Without 'WriteChar' we cannot help further.
Paul
The problem exists in your WriteChar macro, you are writing the total length of the string instead of 1.
I imageing that in that macro you are looping until you hit a null byte. just make it print a single byte!!
-Brian
I imageing that in that macro you are looping until you hit a null byte. just make it print a single byte!!
-Brian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
just a thought, you might need to change this line:
mov esi, offset hello + [ecx] ;put text into esi
I think that might give error, since ecx = 0 and [] means from address of..
so you could try changing it to:
lea esi, offset hello
add esi, ecx
:)
mov esi, offset hello + [ecx] ;put text into esi
I think that might give error, since ecx = 0 and [] means from address of..
so you could try changing it to:
lea esi, offset hello
add esi, ecx
:)
It seems WriteChar outputs everything from the starting position until a null (0). You'll have to fix that routine or use a different one.