Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6948673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:51:13+00:00 2026-05-27T13:51:13+00:00

I am trying to print a string in assembly by calling printf. My assembly

  • 0

I am trying to print a string in assembly by calling printf.

My assembly code:

mov dword[ebx + 0], '"'
mov dword[ebx + 4], 'h'
mov dword[ebx + 8], 'e'
mov dword[ebx + 12], 'l'
mov dword[ebx + 16], 'l'
mov dword[ebx + 20], 'o'
mov dword[ebx + 24], '"'
mov dword[ebx + 28], 0
push ebx
push formatString
call printf
add esp, 8
...
formatString    db    '%s', 10, 0

However when I run this it only prints the first character – ‘”‘, not the whole word (“hello”).

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:51:14+00:00Added an answer on May 27, 2026 at 1:51 pm

    My assembly is rusty, but those should probably be byte-wise moves. You need a byte array in memory since that is what printf is expecting for a %s. The string in memory is probably "\0\0\0h\0\0\0e\0\0\0l\0\0\0l\0\0\0o\0\0\0"\0\0\0\0\0\0\0.

    mov dword[ebx + 0], '"'        ; moves the 32-bit value 0x22000000 to EBX
    mov dword[ebx + 4], 'h'        ; moves the 32-bit value 0x68000000 to EBX + 4
    ...
    

    So, if ebx contains the address 0x123456, then you would have something like the following in memory:

    0123456 | 22 00 00 00  68 00 00 00   65 00 00 00  6c 00 00 00 | "...h...e...l... |
    0123466 | 6c 00 00 00  6f 00 00 00   22 00 00 00  00 00 00 00 | l...o..."....... |
    

    Even though you are passing 0x123456 into printf as the address, it is only seeing a single character before it hits the first NUL byte. The following should work:

    mov dword[ebx + 0], 577267052   ; 0x2268656c = "hel
    mov dword[ebx + 4], 1819222528  ; 0x6c6f2200 = lo"\0
    push ebx
    push formatString
    call printf
    add esp, 8
    

    There is probably a much better way to load bytes into an indirect address based on ebx but I haven’t looked at assembly in more years than I can count.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm trying to write some assembly code that uses printf to print a
In Ruby, trying to print out the individual elements of a String is giving
I'm trying to read in a multi line string then split it then print
In this code: soup=BeautifulSoup(program.Description.encode('utf-8')) name=soup.find('div',{'class':'head'}) print name.string.decode('utf-8') error happening when i'm trying to print
I have two string variables ticker and detail. I'm trying to print out the
I'm trying to copy a string using 16-bit assembly. I have (among other things)
Im trying to debug the following code using System; public class Parent { string
I have a string I am trying to print. when I used cout ,
I am trying to print a unicode string without the specific encoding hex in
I'm trying to make this program in assembly. It should just convert a string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.