nasm

Win32 Assembly - Extern function naming (The meaning of '@')

孤街醉人 提交于 2019-12-12 02:42:31
问题 As I see, extern WinAPI functions in assembly code have names like _ExitProcess@4 . What is the meaning of the @4 part, and how to determine what number to use after @ ? I know that this has something to do with DLL we are linking against, but in many cases it's not known what number to use after the @ , and this leads to many nasty undefined reference errors. 回答1: As Andreas H answer said the number after the @ is the number of bytes the function removes from stack before the function

Use procedure scope to avoid local labels?

房东的猫 提交于 2019-12-12 02:28:56
问题 I ported some MASM code to NASM. The port was fairly painless, except for the need for local labels. The local labels were needed because the MASM code had multiple procedures, and some labels were common to the procedure. For example ;; MASM code _FOO PROC ... Exit_Failure: ... Exit_Success: ... ret _FOO ENDP _BAR PROC ... Exit_Failure: ... Exit_Success: ... ret _BAR ENDP Under NASM, I have to use local labels. For example: ;; NASM code global _FOO section .text _FOO: ... .Exit_Failure: ...

Appending a File with int 0x80 (Access bits?)

断了今生、忘了曾经 提交于 2019-12-12 02:27:24
问题 In my NASM textbook, "Guide to Assembly Programming in Linux" by Dandamundi, system call 5 (opening a file) is described with the following parameters. EAX = 5 EBX = file name ECX = file access mode (read, write, read/write) EDX = file permissions It does not clarify what the access codes (octal, I'm assuming) actually are. 0200Q and 02000Q assumedly do not work. I am trying to append the contents of one file onto another file. 回答1: After looking at /usr/include/asm/unistd_32.h , it's clear

nasm issue relocation R_X86_64_PC32 shared library

拟墨画扇 提交于 2019-12-12 02:24:19
问题 I am using nasm 64 to compile .S to .o and then create a shared library with gcc like this: nasm -f elf64 source/strlen.S nasm -f elf64 source/strchr.S nasm -f elf64 source/memset.S nasm -f elf64 source/strcspn.S nasm -f elf64 source/rindex.S nasm -f elf64 source/strpbrk.S nasm -f elf64 source/strcmp.S nasm -f elf64 source/strncmp.S nasm -f elf64 source/strcasecmp.S /usr/bin/gcc -shared ./source/strlen.o ./source/strchr.o ./source/memset.o ./source/strcspn.o ./source/rindex.o ./source/strpbrk

db usage in nasm, try to store and print string

余生长醉 提交于 2019-12-12 01:58:25
问题 I was trying to store a few strings in my assembly, and use WriteString to print out on the screen. However, I only call one of the strings, it shows up all of them in one single line. Why does this happen? Is that anything wrong in my code? Thanks! Code here: %include "lib/libasm.h" SECTION .text global main main: call badrng ret badrng: push eax push edx mov edx, badrngstr call WriteString pop edx pop eax call failure ret failure: mov eax,1 int 0x80 ret SECTION .data nlstr: db "" badrngstr:

How do I test to ensure only an integer is entered and ensure length of input is 5 bytes or less in Assembly?

徘徊边缘 提交于 2019-12-11 23:34:27
问题 How do I test to ensure only an integer is entered and ensure length of input is 5 bytes or less in the following code? I am trying to understand how to properly control input so that the input beyond 5 bytes is not outputted to the terminal upon exiting of the program. In addition, how would I test to ensure only a string is entered and finally in the last scenario, only a double is entered? *** Updated code based on x82 and Peter C's guidance. I did some C disas and was able to amend my

Why does address range 0xC0000000 ~ 0xFFFFFFFF always give 0x00 or 0xFF after switching to protected mode before enabling paging?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 19:09:14
问题 I'm making a custom boot loader, and currently in the stage of enabling paging after switching to protected mode. I tried to check all memory range is usable from 0x00000000 to 0xFFFFFFFF to make sure my kernel has full control over memories. Checking is done by copying value to the memory address and printing the value through video memory(0xB8000). But the address range from 0xC0000000 to 0xFFFFFFFF always contains 0x00(if executed by QEMU) or 0xFF(if executed in real hardware through

How to add in assembly?

末鹿安然 提交于 2019-12-11 18:35:13
问题 I am trying to make a calculator in assembly. You introduce two variables and then you choose the operation. Now the operation is only addition. I am working only with BIOS interrupts, no DOS. Can someone explain to me how to make it? I have two problems and I am stuck with them: The first problem is when I add 5+6 for example it returns 59(48+11) in ASCII. I think a solution would be to print in decimal but I found nothing on the internet using only BIOS interrupts. The second problem is

Assembly - Reserve array space during program?

瘦欲@ 提交于 2019-12-11 18:08:08
问题 I am in the middle of an assembly program and I want to declare an array. I have the array size in a register and I know the type of the elements (i.e. how many bytes each element is) - how can I reserve space in the heap for this array (and then access particular elements)? Do I need to call malloc? 回答1: "malloc()" is a creature of the C runtime library. You can certainly call "malloc()" from assembly ... provided you initialize the C runtime system first. C and C++ both do this

The value displayed in Kdbg is wrong — NASM

别说谁变了你拦得住时间么 提交于 2019-12-11 17:56:02
问题 How can I test to see if the value of k is correct? section .data k dw 5 m dw 110 rez dw 0 section .bss tabela resq 3 section .text global _start extern uslov _start: mov qword [tabela], k mov qword [tabela + 8], m mov qword [tabela + 16], rez mov rbx, tabela call uslov mov rax, 60 mov rdi, 0 syscall When I try to inspect the values of k,m,rez in kdbg the values of m and rez are just fine but the value of k is totally different, now at first i thought it was random, but it seems as tough it