Reputation: 807 Master
- Active Posts:
- 2,235 (2.26 per day)
- 28-March 11
- Profile Views:
- Last Active:
- Today, 08:20 AM
- OS Preference:
- Favorite Browser:
- Favorite Processor:
- Favorite Gaming Platform:
- Your Car:
- Who Cares
- Dream Kudos:
- Expert In:
Yesterday, 09:52 PM
03 Dec 2013 - 20:43
26 Nov 2013 - 20:23
25 Nov 2013 - 20:15
24 Nov 2013 - 23:10
24 Nov 2013 - 20:18
18 Nov 2013 - 20:23
14 Nov 2013 - 17:58
12 Nov 2013 - 22:39
12 Nov 2013 - 11:26
Posts I've Made
Posted 8 Dec 2013Dup closed...
Posted 8 Dec 2013If you open irvine32.inc, the option line should be there but commented out. Not sure why, but it is there.
There are a few issues...
1. You stack is not correct. You set up a stack frame correctly, but do not unwind it correctly!!
Correct prologue (which you have):
push ebp ; set ebp mov ebp, esp sub esp, 16 ; save room for 4 local variables
Your epilogue is wrong...
add esp, 16 pop ebp ret 16
Notice something missing there? Whatever you do in the prologue, you must reverse in the epilogue! You are not setting esp back to its original value!!
add esp, 16 mov esp, ebp ; <<<<<<<<<<<<<<< Need this!!! pop ebp ret 16
Same goes for the epilogue of display, you need to set esp back to its original value.. Also, you are using stdcall so your ret is wrong at the end of display, it should be ret 8 since you are passing 2 dword on the stack as parameters.
Now, as for your code being off by one... Your code is correct and doing what you tell it to do. Your taking the address of the array and scanning for 100 and storing the next address into a local var... So you are not storing the address of the first line of the array in the local var, but the second. You need to store the base address before your scasb...
sub ebx, 4 ; first local var StoreAddr: mov [ebx], edi ; save address of first line storeAdrr: repne scasb ; repeat while not equal sub ebx, 4 ; ebp - 4 mov [ebx], edi ; store address in local variable dec edx cmp edx, 0 jne storeAdrr
This is why I do not use any rep prefixes but code my own loops for full control...
Posted 8 Dec 2013Assembler reserved words, instructions, registers etc.. are not case sensitive, but variable names, label names and procedure names ARE... It is for good reason too, cuts down on bugs.
Posted 8 Dec 2013Tell you what, if you fix the following errors, I will look over you code. It is almost 12 am and I have to work in the morning so you don't have much time to post the corrected code.
Assembly is strict on Case...
You create a procedure called display, but yet call it with call Display. Irvine named his functions WriteDec, but yet you use writedec in your code... same for WriteChar... I am not going to go through your code fixing all the typos...
At the top of your source file add this line:
OPTION CASEMAP:NONENow try to Assemble, you should get many errors. Go fix those errors and post the correct code.
Posted 6 Dec 2013Since you are just started learning Assembly, let's go over a few things to get you started on the "right" foot!!
Kudos for comments!!! Even though a few are wrong, it is a great start since many newbies do not comment their code!!
Many programmers HATE "magic numbers"!!! I am one of them. DO NOT USE THEM!!! Get into the habit of using named constants instead of numbers. Why you ask? Simple, if you need help with your code, and you show it to someone or on a forum, we don't have to guess what the numbers mean. Also, it makes your self documenting and easier to update later on. How? Let's say you have a buffer that is 100 bytes, and everywhere you use this buffer size is the number 100; well, if you update your code and make that buffer say 256 bytes, you will need to search and replace every where in your code that 100 is used for the buffer size and hope you don't change the wrong 100. Instead, if you do:
%define INPUT_BUFFER_LEN 100 section .bss lpInputBuffer resb INPUT_BUFFER_LEN
and use INPUT_BUFFER_LEN instead of a hard coded 100 everywhere in your code, when and if you change the buffer size, all you need to change is the define for INPUT_BUFFER_LEN.
Use meaningful variable names!!! There isn't really a limit on length of a variable name. You use var... What is it? Maybe use Input_Number?? You use len... len of what?? We could do MSG_LEN, INPUT_LEN, etc...
System calls all have names... Use them...
mov edx, 8 ; i thik cpu save the value for this 32bit mov ecx, var ; cpu will send the value to var integer mov ebx, 0 ; i still dont know what it is but its piece of reading code mov eax,3 ; uncle kernel int 0x80 ; we there, if computer asks are we there yet?
A better way:
%define sys_read 3 %define stdin mov edx, INPUT_LEN ; how many bytes to read mov ecx, Input_Buffer ; address of buffer to read to mov ebx, stdin ; where are we reading from??? mov eax, sys_read ; system call int 80H
Here is a little trick to make an include file of all the system call names and numbers:
For 32 bit system, open a terminal and type:
locate unistd32.h and hit enter, a few different directories should show up. On my system the first path returned is:
Now, replace PATH_TO_UNISTD_32H with one of the paths locate returned, in the following command:
grep __NR PATH_TO_UNISTD_32H | grep define | sed -e 's/\#/\%/' -e 's/__NR_/sys_/' > unistd_32.inc
cd to your desktop or include directory and run that command... on my system it would be:
grep __NR /usr/include/i386-linux-gnu/asm/unistd_32.h | grep define | sed -e 's/\#/\%/' -e 's/__NR_/sys_/' > unistd_32.inc
You now have an include file with a bunch of defines for the system call names and numbers. Now you just have to %include this file at the top of your source file to use the named sys calls in your source.
For 64 bit systems, is is almost the same.. use locate unistd_64.h
grep __NR /usr/include/x86_64-linux-gnu/asm/unistd_64.h | grep define | sed -e 's/\#/\%/' -e 's/__NR_/sys_/' > unistd_64.inc
Oh, and how did you fix your problem??? This way others with the same issue can use your fix...
- Member Title:
- "Hurry up and wait"
- 39 years old
- June 30, 1974
- In my head
- Forum Leader:
- Full Name:
- Years Programming:
- Programming Languages:
- x86 Win32 Assembly (MASM, FASM, NASM)