assembly

Subtracting two characters

我的未来我决定 提交于 2021-02-16 18:13:12
问题 I just started programming in assembly so I am a beginner. To practice, I am trying to rewrite a basic libc in assembly (NASM Intel syntax). But I'm stuck on the strcmp function: ;; Compare two C-style NUL-terminated strings ;; Inputs : ESI = address of s1, EDI = address of s2 ;; Outputs : EAX = return an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2 strcmp: call strlen mov ecx, eax ; ecx = length of the string

How to input from user number more than one digit in assembly?

懵懂的女人 提交于 2021-02-16 17:54:35
问题 I need to find an interrupt that can receive from a user a number with more than 1 digit. ;code mov [0],0 mov si,0 lop: mov ah,1 int 21h cmp al,'q' je finishedInput xor ah,ah add [word ptr si], ax jmp lop finishedInput: I have already tried to do an end less loop that each time uses the mov ah,1 int 21h combination until the user press 'q' and the endless loop will stop and. However, I am almost convinced that I have seen a code that do the same thing with interrupt instead. I want to stop

What is the function of a “data label” in an x86 assembler?

帅比萌擦擦* 提交于 2021-02-16 16:41:21
问题 I'm currently learning assembly programming by following Kip Irvine's "assembly language x86 programming" book. In the book, the authors tries to explain the concept of data label A data label identifies the location of a variable, providing a convenient way to reference the variable in code. The following, for example, defines a variable named count: count DWORD 100 The assembler assigns a numeric address to each label. So my understanding of what data label does is: data label count is a

x86_64 Opcode encoding formats in the intel manual

試著忘記壹切 提交于 2021-02-16 14:04:29
问题 What are the "Op/En" formats listed in the Intel x86_64 reference manual? For example in the Add opcode I can take a guess at some such as "I" = Immediate, but is there a comprehensive list for these? 回答1: The intro sections of Intel's vol.2 manual explain how to read each entry: Section 3.1.1.4 Operand Encoding Column in the Instruction Summary Table The “operand encoding” column is abbreviated as Op/En in the Instruction Summary table heading. Instruction operand encoding information is

Understanding GCC's floating point constants in assembly listing output

陌路散爱 提交于 2021-02-16 13:45:08
问题 Just out of curiosity, I'm using Compiler Explorer to see the assembly output of some simple C++ codes. Consider the following example int main(void){ double x = -5.3; } Assembly output main: push rbp mov rbp, rsp movsd xmm0, QWORD PTR .LC0[rip] movsd QWORD PTR [rbp-8], xmm0 mov eax, 0 pop rbp ret .LC0: .long 858993459 .long -1072352461 I would like to understand how to use .LC0: .long 858993459 .long -1072352461 to get back my -5.3 . My uninformed guess is that I need to merge the bit

“Hacking: The Art of Exploitation” - Assembly Inconsistencies in book examples vs. my system's gcc

怎甘沉沦 提交于 2021-02-16 09:18:07
问题 I am studying "Hacking: The Art of Exploitation". I am trying to follow the code examples, but for some reason the assembly codes simply does not match the one on my actual Linux (running on Virtual Box as Guest). I have made sure that I have installed 32 bit Linux OS. Is there any args that I can pass to gcc that lets me compile the code into an assembly that matches closely with the ones given in the book? I would be fine reconciling the code differences between the book & what I see if

What is the explanation of this x86 Hello World using 32-bit int 0x80 Linux system calls from _start?

我的梦境 提交于 2021-02-15 07:50:37
问题 section .text global _start ;must be declared for using gcc _start: ;tell linker entry point mov edx, len ;message length mov ecx, msg ;message to write mov ebx, 1 ;file descriptor (stdout) mov eax, 4 ;system call number (sys_write) int 0x80 ;call kernel mov eax, 1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'Hello, world!',0xa ;our dear string len equ $ - msg ;length of our dear string This is a basic 32-bit x86 Linux assembly code to print "Hello, World!" on

What is the explanation of this x86 Hello World using 32-bit int 0x80 Linux system calls from _start?

谁说我不能喝 提交于 2021-02-15 07:50:13
问题 section .text global _start ;must be declared for using gcc _start: ;tell linker entry point mov edx, len ;message length mov ecx, msg ;message to write mov ebx, 1 ;file descriptor (stdout) mov eax, 4 ;system call number (sys_write) int 0x80 ;call kernel mov eax, 1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'Hello, world!',0xa ;our dear string len equ $ - msg ;length of our dear string This is a basic 32-bit x86 Linux assembly code to print "Hello, World!" on

How to characterize a workload by obtaining the instruction type breakdown?

醉酒当歌 提交于 2021-02-15 07:44:35
问题 I want to obtain the percentage of memory read-write instructions in a test program, preferably dynamically. Apart from counting instructions in the gdb asm dump, which is static anyway, is there an easier way to obtain it? Valgrind provides total heap usage. Perf has some nice features but does not support WSL. Pin has an instruction count capability but it I am not sure if it supports WSL. 回答1: (Update: PIN reportedly doesn't work under WSL. But it doesn't require perf counters so it's

NASM Segmentation fault when modifying a variable that should be in the read-write .data section (section .data doesn't work without a space?)

余生长醉 提交于 2021-02-15 07:40:23
问题 I'm having an issue with a program I'm writing in NASM using SASM, I'm using a variable as a counter and once I modified it and try to to save the new value at the used address in memory I get a segmentation fault. Here are the bits of code concerning the variable: section.data p_count DW 0 section.text global CMAIN CMAIN: mov ebp, esp; for correct debugging mov bx, [p_count] inc bx mov [p_count], bx ret The program stops running when it arrives at the last line here. Anyone has an idea what