Solved

accessing character in Assembly language

Posted on 2004-10-03
9
1,722 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
 

Author Comment

by:sgbrt
ID: 12218113
LRHGuy, thanks but doesn't work!
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now