Untitled
unknown
plain_text
2 years ago
2.2 kB
9
Indexable
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <locale.h>
#pragma warning( push, 4 )
//__declspec(naked) size_t MyStrlen(const char* str)
//{
// __asm
// {
// /*push eax; size
// call malloc
// pop ecx
// ret*/
// or eax, -1
// mov edx, [esp + 4]; str
// _whi : inc eax; ptr++
// cmp byte ptr[edx + eax], 0; *ptr ? '\0'
// jne _whi
// ret
// }
//}
__declspec(naked) char* MyStrchr(const char* str, char ch)
{
__asm
{
or eax, -1
mov eax, [esp + 4]; str
mov cl, [esp + 8]
_whi : inc eax; ptr++;
cmp byte ptr[eax], 0; *ptr ? '\0'
je _ola
cmp byte ptr[eax], cl; *ptr ? '\0'
jne _ala
jne _whi
_ola: mov eax, 0
_ala:
ret
}
}
int main(void)
{
(void)setlocale(LC_ALL, "pl-PL");
//{
// int a, b, c;
// (void)scanf("%d", &a);
// (void)scanf("%d", &b);
// // c = a + b
// __asm
// {
// mov eax, b
// add eax, a
// mov c, eax
// }
// printf("\n%d\n", c);
//}
//{
// unsigned short a, b, c;
// (void)scanf("%hu", &a);
// (void)scanf("%hu", &b);
// printf("Wprowadziłeś a=%hu, b=%hu", a, b);
// // c = a / b
// __asm
// {
// mov ax, a
// mov dx, 0
// div b
// mov c, ax
// }
// printf("\n%hu\n", c);
//}
//{
// int a, b, c;
// (void)scanf("%d", &a);
// (void)scanf("%d", &b);
// printf("Wprowadziłeś a=%d, b=%d", a, b);
// // c = a / b, sprawdzić dla a=-6 i a=2
// __asm
// {
// mov eax, a
// cdq
// idiv b
// mov c, eax
//
// }
// printf("\n%d\n", c);
//}
//{
// unsigned num, bits;
// // dla num=0x12345678, bits = 4 => 23456781
// (void)scanf("%x", &num);
// (void)scanf("%u", &bits);
// __asm
// {
// mov ecx, bits
// rol num, cl
// }
// printf("\n%x\n", num);
//}
//{
// char buf[50];
// fgets(buf, sizeof(buf), stdin);
// buf[strlen(buf) - 1] = '\0'; // \n
// printf("\n%zu %zu\n", strlen(buf), MyStrlen(buf));
//}
{
char buf[50], ch;
fgets(buf, sizeof(buf), stdin);
(void)scanf("%c", &ch);
char* ptr = MyStrchr(buf, ch);
if (ptr == NULL)puts("Nie znaleziono");
else printf("\nZnaleziono na pozycji [%d]\n", ptr - buf);
}
return EXIT_SUCCESS;
}
#pragma warning(pop)Editor is loading...
Leave a Comment