Solved

accessing character in Assembly language

Posted on 2004-10-03
9
1,766 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reverse Engineering Assembly Code 17 1,755
gcc error: -mpreferred-stack-boundary=2 is not between 4 and 12 7 1,940
MIPS Assembly 8 535
Remove duplicates in a continuous form 3 10
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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