| | |
Convert C code to Assembly code
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 1
Reputation:
Solved Threads: 0
Hello, I tried to convert below code, but I couldn't.. What is wrong?
--------------------------------------------------
please help me....thanks...
c Syntax (Toggle Plain Text)
void invert(unsigned char *image, int width, int height){ for(int i=0;i<width*height;i++) image[i]=255-image[i]; }
assembly Syntax (Toggle Plain Text)
---------------------ASM--------- invert PROC push ebp ; save ebp register mov ebp,esp ; get current stack pointer mov esi,[ebp+8] ; get first parameter mov eax,[ebp+12] ; get second parameter mov ebx,[ebp+16] ; get third parameter mul ebx ; eax=eax * ebx mov ecx,eax ; get image size dec ecx mov al,255 L1: sub al,[esi] ; al=al-image[i] mov [esi],al ; image[i]=al inc esi loop L1 pop ebp ; restore ebp ret ; return to caller invert ENDP
please help me....thanks...
Last edited by Ancient Dragon; May 2nd, 2008 at 4:54 pm. Reason: add code tags
Actually that's not correct, you did convert it and a reasonably good job too, the only problem is it's not working as expected.
1. You only initialize AL to -1 (255 or 0FFH) once and then inside your loop it's modified.
Note: mov [esi], al and then incrementing ESI is not wrong, it's just STOSB saves code space.
1. You only initialize AL to -1 (255 or 0FFH) once and then inside your loop it's modified.
asm Syntax (Toggle Plain Text)
L1: push eax sub al, [esi] stosb pop eax loop L1
Note: mov [esi], al and then incrementing ESI is not wrong, it's just STOSB saves code space.
![]() |
Similar Threads
- Conversion from C++ to MIPS Assembly (Assembly)
- C++ code to MIPS code (assembly) (C++)
- need help convert MASM to ASM 8086 (Assembly)
- I need help covert my source code frm pic16c54a to pic16f84a (Assembly)
- Converting Java to C (Java)
- C++ to ASM (C++)
- Converting without additional headers (C)
- Doesnt really make sense (Assembly)
- Introduction to 80 x 86 Assembly Language and Computer Architecture - no CD - help (Assembly)
Other Threads in the Assembly Forum
- Previous Thread: How define a temprary register/variable in x86 assembly? help needed
- Next Thread: C code to Assembly code
| Thread Tools | Search this Thread |
Tag cloud for Assembly
3d 68hc11 6811 80386 adress array asm assembler assembly boot bootloader buffer compression cursor debug directory division docs dos draw emulator endtask error exceptions file int10h integer intel interrupt interrupts language loop nohau osdevelopment print program range read remainder shape string text theory tsr x86





