Solved

accessing character in Assembly language

Posted on 2004-10-03
9
1,757 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
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
If there a quick way to convert a cardinal value into 4, 8-bit bytes? 7 526
Show semaphore name in Pascal 12 644
#if defined in C Source File ??? 12 453
Crystal Report for VS2013 17 129
Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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