Question about low level shellcode

Type your comment> @yb4Iym8f88 said:

1st: Do not use strlen as a method to calculate the length of shellcode. _countof or sizeof would be better here.
2nd: Have you checked the architecture of shellcode you used? x86/x64?
3rd: Have you had the stack executable in gcc when you compiled the example given (c - What is the -z option for in this gcc compiler command? - Stack Overflow)? I think it could be an issue here.

1: Ok, I will in the future.
2: I compiled the shellcode by doing the following:
- write the assembly instructions to a file called shellcode.asm
- compile shellcode.asm into shellcode.o with the following command: nasm -f elf32 shellcode.asm -o shellcode.o
- link shellcode.o to an executable with the following command: ld -m elf_i386 -s shellcode.o -o shellcode
- extract the raw machinecode bytes by using the following command: objdump -d shellcode

3: after I extracted the bytes as described above, I pasted them in the c-code from my first post. Then i compiled the c-file with the following command: gcc tst.c -o shell -fno-stack-protector -z execstack -no-pie -m32. I expected that the executable would give me an sh shell, but instead it gives a segfault. When i run the binary which was created by linking the shellcode.o file(generated by nasm), it works just as intended. It might very well be that the assembly I used just isn’t correct, since I have found another example shellcode which did work, only it contained to many bytes to be useful to me.

What am I missing here? I think i did everything correctly right? Sorry for the long response, just trying to be as clear as possible.