Solved

accessing character in Assembly language

Posted on 2004-10-03
9
1,778 Views
Last Modified: 2010-10-05

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


0
Comment
Question by:sgbrt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12213138
You don't show the WriteChar routine, which is the "culprit".

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.
0
 

Author Comment

by:sgbrt
ID: 12213156
I tried using WriteString, but didn't work!
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12213471
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


0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:sgbrt
ID: 12218113
LRHGuy, thanks but doesn't work!
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12218139
So, what does it do?

Can you show me the WriteChar routine?
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 12218755
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
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 12431267
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
0
 
LVL 8

Accepted Solution

by:
craigwardman earned 100 total points
ID: 14631539
Hello, I know this is an old question, but its not closed and ive run out of questions to answer :)

You can solve the above problem by only reading one char at a time, and finishing it off with a null char ( 0 )..

As follows:

include irvine32.inc    

.data

hello byte "HELLO WORLD",0  ; message to write
buf db 2 dup(0)           ;this is MASM syntax to define 2 bytes, not sure if works on all compilers

.code

main proc
  call Clrscr
  call Crlf  
 
  xor ecx, ecx
NEXTLETTER:
  mov esi, offset hello + [ecx]       ;put text into esi
  lea edi, buf                           ;assign 2byte buffer
  movsb                            ;move 1 character (ESI --> EDI)
  mov byte ptr [edi], 0        ;append a 0 (nullchar) [dont use +1, since movsb has incremented edi]
  dec edi                           ;get back to character position
  mov ebx, edi                   ;assuming that WriteChar is using ebx register
  pushad                           ;save all registers incase modified in macros
  call WriteChar  
  call Crlf
  popad                            ;get our registers back
  cmp ecx, 0Bh                  ;11 characters
  je EOW
  inc ecx
  jmp NEXTLETTER

EOW:

  exit                 ; a macro that calls ExitProcess
main endp

end main


I havent tested that, since I havent got those macros and havent got a quick way to re-write the code to output characters, but something along those lines should work..
0
 
LVL 8

Expert Comment

by:craigwardman
ID: 14631560
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

:)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Gain an elementary understanding of Blockchain technology.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question