assembly

distinguishes between signed and unsigned in machine code

浪子不回头ぞ 提交于 2021-01-28 10:50:18
问题 I was reading a text book saying: It is important to note how machine code distinguishes between signed and unsigned values. Unlike in C, it does not associate a data type with each program value. Instead, it mostly uses the same (assembly)instructions for the two cases, because many arithmetic operations have the same bit-level behavior for unsigned and two’s-complement arithmetic. I don't understand what it means, could anyone provide me an example? 回答1: For example, this code: int main() {

Printing decimal number in assembly language?

本秂侑毒 提交于 2021-01-28 10:27:36
问题 I'm trying to get output in decimal form. Please tell me what I can do to get the same variable in decimal instead of ASCII. .model small .stack 100h .data msg_1 db 'Number Is = $' var_1 db 12 .code add_1 proc mov ax, @data mov ds, ax mov ah, 09 lea dx, msg_1 int 21h mov ah, 02 mov dl, var_1 int 21h mov ah, 4ch int 21h add_1 endp end add_1 回答1: These 3 lines that you wrote: mov ah, 02 mov dl, var_1 int 21h print the character represented by the ASCII code held in your var_1 variable. To print

Printing decimal number in assembly language?

房东的猫 提交于 2021-01-28 10:24:34
问题 I'm trying to get output in decimal form. Please tell me what I can do to get the same variable in decimal instead of ASCII. .model small .stack 100h .data msg_1 db 'Number Is = $' var_1 db 12 .code add_1 proc mov ax, @data mov ds, ax mov ah, 09 lea dx, msg_1 int 21h mov ah, 02 mov dl, var_1 int 21h mov ah, 4ch int 21h add_1 endp end add_1 回答1: These 3 lines that you wrote: mov ah, 02 mov dl, var_1 int 21h print the character represented by the ASCII code held in your var_1 variable. To print

Integer describing number of floating point arguments in xmm registers not passed to rax

安稳与你 提交于 2021-01-28 09:30:59
问题 I have got a function which is declared as follows: double foo(int ** buffer, int size, ...); The function is a part of cpp implementation of a program. I use last parameter to pass multiple double variables to the function. The problem is that on Mac I do not receive valid number in rax register, on the other hand on ubuntu it works as expected. A simple example: CPP #include <iostream> extern "C" double foo(int ** buffer, int buffer_size, ...); int main() { int* buffer [] = {new int(2), new

Shorter x86 call instruction

半腔热情 提交于 2021-01-28 09:26:52
问题 For context I am x86 golfing. 00000005 <start>: 5: e8 25 00 00 00 call 2f <cube> a: 50 push %eax Multiple calls later... 0000002f <cube>: 2f: 89 c8 mov %ecx,%eax 31: f7 e9 imul %ecx 33: f7 e9 imul %ecx 35: c3 ret call took 5 bytes even though the offset fit into a single byte! Is there any way to write call cube and assemble with GNU assembler and get a smaller offset? I understand 16 bit offsets could be used, but ideally I'd have a 2 byte instruction like call reg . 回答1: There is no call

What are techniques for determining running OS in assembly language at runtime?

一个人想着一个人 提交于 2021-01-28 09:18:14
问题 What are techniques for determining running OS in assembly language at runtime? If there are direct ways to determine this, that'd be awesome. I was also thinking of how there are tricks in Javascript to determine what browser you're running in... Are there similar techniques for determining OS or even CPU arch in a low level language like Intel assembly? Thanks, Chenz 回答1: CPU architecture will be next-to-impossible to determine. Machine code differs greatly between CPU architectures, and so

x86 MASM Assembly - Input Buffer holds old input despite FlushConsoleInputBuffer

余生长醉 提交于 2021-01-28 09:18:04
问题 To practice assembly in MASM, I created a small program that is supposed to do the do the following: Print "Type a: " to the screen Read one character from the input buffer, which is then flushed If the character is "a", then break away from the loop and end the program, if otherwise, repeat from step one My code goes as follows: .386 .model flat,stdcall include \masm32\include\kernel32.inc ; Defines Symbols To Be Used for the kernel32 library includelib \masm32\lib\kernel32.lib STD_OUTPUT

Why Segment fault when writing to writeable .data section? Using Ubuntu, x86, nasm, gdb, readelf

给你一囗甜甜゛ 提交于 2021-01-28 09:01:13
问题 I'm learning to write a simple shell code using assembly. I get a Segment fault when the mov opcode executes to write over the db data. Why? Any guidance appreciated! Debugging with gdb confirms the data is contiguous with the code at run time and readelf analysis of the program confirms the data segment is writeable. section .text global _start _start: ; The following code calls execve("/bin/sh", argv, envp=0) jmp short two one: pop ebx xor eax, eax mov [ebx+12], eax mov [ebx+7], al mov [ebx

Define new code section in assembly code to compile ELF binary

 ̄綄美尐妖づ 提交于 2021-01-28 08:06:41
问题 I defined a new code section in my assembly program, which is going to be compiled into 32-bit ELF binary, on x86. I use the linker scripts to assign a specified address for this new code section, it works. However, I noticed that this new section does not be loaded to the memory, after some debugging! I use readelf and figure out that there is no "execution" privilege of this new section: [15] .trampoline PROGBITS 080483d0 004020 000117 00 0 0 16 Then I did this: objcopy --set-section-flags

Assembly code do not recognise ? and @data

别来无恙 提交于 2021-01-28 08:04:28
问题 It is my first assembly program. Can anyone please help to make it run successfully. I am seeing below compilation error. Why it do not recognize the ? and @data ? I am trying to swap two variables in assembly. I am executing the following command nasm -f elf swap.asm But I get this error: swap.asm:6: error: symbol `?' undefined swap.asm:12: error: symbol `@data' undefined swap.asm:15: error: invalid combination of opcode and operands swap.asm:21: error: invalid combination of opcode and