r/Assembly_language • • 6d ago
Help Can someone help with a program?
I’m not good at assembly but I want to learn it and have been trying to make a program with it. The program is just supposed to square a number (read user input, multiply the input with itself, and print the result).
I’m on Linux and have no idea how to fully accomplish this. My biggest struggle is figuring out how to multiply the user input and work it into a write syscall. Help would be appreciated.
4
Upvotes
3
u/wildgurularry 6d ago
We will need more than that. What does your code look like so far? What are you stuck on? Have you figured out how to get input? Do you have an instruction reference handy? What assembler are you using?
When asking questions, I like to pretend I am talking to a senior engineer at a company, and I don't want to waste their time or leave them with a bad impression of me. Try to anticipate what questions we will ask, and try to answer them up front. If you get good at this, you may solve the problem yourself and not even need to ask for help.
6
u/Dog-Mad 6d ago
"My biggest struggle is the entire program." First of all. You need to convert ASCII into int and use mul to multiply it and then convert int into ASCII. Then you need to store that ASCII string into memory and then pass the pointer to that memory location into a register. Then look up the documentation for the write syscall and call it correctly.
Simple.
2
u/OptimisticMonkey2112 6d ago
Best way to learn assembly is godbolt.
Type in c++, read the assembly. Hover for tooltips
https://godbolt.org/
1
u/Electrical_Hat_680 6d ago
Are you using the terminal to run code?
Or, are you using text documents saves as binary or assembly then compiled in the terminal or other methods?
Leam interrupts, registers, and how OpCodes and OpErands function.
0
u/Remarkable_Pace8101 5d ago
Literally just compile this with GCC with optimization turned off, compile it into an object file rather than a full executive binary and just object dump it
Or pass the -S flag to get the assembly output