Reputation: 866 Master
- Active Posts:
- 2,434 (1.78 per day)
- 28-March 11
- Profile Views:
- Last Active:
- Today, 12:45 PM
- OS Preference:
- Favorite Browser:
- Favorite Processor:
- Favorite Gaming Platform:
- Your Car:
- Who Cares
- Dream Kudos:
- Expert In:
30 Nov 2014 - 17:11
20 Nov 2014 - 09:17
16 Nov 2014 - 10:29
11 Nov 2014 - 08:02
07 Nov 2014 - 11:46
05 Nov 2014 - 20:25
01 Nov 2014 - 15:30
28 Oct 2014 - 19:34
22 Oct 2014 - 17:49
22 Oct 2014 - 04:48
Posts I've Made
Posted 21 Dec 2014Thank you all!
No2, I was told a few times that when I do get a ring for her, that it should be bigger than any of her cousins.
Posted 16 Dec 2014I swapped something from one line with another to get the correct output:
12-16-2014 10-05-43 PM.png (6.11K)
Number of downloads: 2
Your variable names are a bit out of whack... You call it sourceStr, but in reality it is the target buffer, no? That being said, your sourceStr (AHEM, target buffer) is not big enough to hold the concatenated strings, so you are overwriting what is after your sourceStr (I mean your target buffer), how would you fix that?
Another thing, registers have functions to them. For instance, si is the source index register (esi - Extended Source Index) di is the destination index register (edi - Extended Source Index Register) So, your source string would go into esi and your target buffer/string would go into edi. One can look at the code and know what is going on. When you put the source into edi, and target into esi, it is a bit confusing.
Let's look at the strcat prototype from the C Library:
char * strcat ( char * destination, const char * source );
So, to be intuitive, your proto should look like:
Str_concat PROTO, destination:ptr byte, source:ptr byte
Next, while programing in Assembly, you need to be aware of what is called an ABI (Application Binary Interface), this dictates what how parameters are passed, where the return value is, if things need to be aligned, who cleans up the stack, and a biggie, what registers need to be saved across a function call and which do not.
The x86 ABI states that if your function uses the non-volatile registers: esi, edi, ebx, ebp, and of course, esp, you must save these in the prologue and restore them in the epilogue. The volatile registers are: eax, ecx, edx and these do not need to be saved. You can save them if you want. This is easy with MASM, you just add uses <registers to save and restore> right after proc. So since your Str_concat uses esi and edi, it should look like:
Str_concat PROC uses esi edi, destination:PTR BYTE, source:PTR BYTE ; your code here ret Str_concat ENDP
and behind the scenes, MASM will do:
push ebp ; prologue mov ebp, esp ; push esi ; push edi ; ; your code here pop edi ; epilogue pop esi ; leave ; ret
All in all, your on the right track, just fix that buffer issue, and you will be good to go.
Posted 3 Dec 2014Moved to Assembly...
Posted 3 Dec 2014Why would you not close the file once you are done?
Posted 27 Nov 2014First thing you don't need to do is save the registers eax, and ecx, they are one of the volatile registers and are allowed to be trashed across function calls.
What terminates almost all strings? A NUL (ASCII 0) right? So how would you check for that? I would make this its own function and use the return value instead of a variable.
include masm32rt.inc .data sstr BYTE "oNe 1 tWO 2 THREE 3 ", 0 .code CheckForCaps: push offset sstr call CountCapitals print str$(eax), 13, 10 inkey invoke ExitProcess, 0 CountCapitals: mov edx, [esp + 4] ; get pointer to string sub edx, 1 ; decrease pointer by 1 xor eax, eax ; zero out NextChar: add edx, 1 ; increase pointer by 1 mov cl, byte ptr [edx] ; move current char into cl test cl, cl ; cl && cl jz Done ; if 0, we are at end of string cmp cl, "A" ; jl NextChar ; if current char is < A (65), repeat loop cmp cl, "Z" ; jg NextChar ; if current char is > Z (90), repeat loop add eax, 1 ; made it here, must be uppercase, increase our counter jmp NextChar ; repeat loop Done: ret 4 * 0 ; adjust stack for 1 parameter, capital count is in eax.
Using your string a input to CountCapitals, line 12 will print 8
- Member Title:
- "Hurry up and wait"
- 40 years old
- June 30, 1974
- In my head
- Forum Leader:
- Full Name:
- Years Programming:
- Programming Languages:
- x86 Win32 Assembly (MASM, FASM, NASM)