assembly

Calling an assembly function from C

旧巷老猫 提交于 2021-02-10 07:44:08
问题 One of my generated functions doesn't compute what it should and I am trying to debug it separately. I have the assembler for it and I try to call it from a stripped down C program. However, for some reason I end up getting segfaults in the function (so, calling the function seems to work, but execution fails). There might be something wrong with passing the arguments.. The functions signature is void func(int, int, float*, float*, float*); The function ignores the first two arguments and

Nasm print to next line

限于喜欢 提交于 2021-02-10 07:14:27
问题 I have the following program written in nasm Assembly: section .text global _start: _start: ; Input variables mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num1 mov ebx, 0 mov eax, 3 int 0x80 mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num2 mov ebx, 0 mov eax, 3 int 0x80 ; Put input values in correct registers mov eax, [num1] sub eax, '0' ; convert char to num mov ebx, [num2] sub ebx, '0' ; convert char to num ; Perform

Nasm print to next line

早过忘川 提交于 2021-02-10 07:12:03
问题 I have the following program written in nasm Assembly: section .text global _start: _start: ; Input variables mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num1 mov ebx, 0 mov eax, 3 int 0x80 mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num2 mov ebx, 0 mov eax, 3 int 0x80 ; Put input values in correct registers mov eax, [num1] sub eax, '0' ; convert char to num mov ebx, [num2] sub ebx, '0' ; convert char to num ; Perform

Nasm print to next line

六眼飞鱼酱① 提交于 2021-02-10 07:11:36
问题 I have the following program written in nasm Assembly: section .text global _start: _start: ; Input variables mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num1 mov ebx, 0 mov eax, 3 int 0x80 mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num2 mov ebx, 0 mov eax, 3 int 0x80 ; Put input values in correct registers mov eax, [num1] sub eax, '0' ; convert char to num mov ebx, [num2] sub ebx, '0' ; convert char to num ; Perform

How can I indicate that the memory *pointed* to by an inline ASM argument may be used?

房东的猫 提交于 2021-02-10 06:56:53
问题 Consider the following small function: void foo(int* iptr) { iptr[10] = 1; __asm__ volatile ("nop"::"r"(iptr):); iptr[10] = 2; } Using gcc, this compiles to: foo: nop mov DWORD PTR [rdi+40], 2 ret Note in particular, that the first write to iptr , iptr[10] = 1 doesn't occur at all: the inline asm nop is the first thing in the function, and only the final write of 2 appears (after the ASM call). Apparently the compiler decides that it only needs to provide an up-to-date version of the value of

How can I indicate that the memory *pointed* to by an inline ASM argument may be used?

百般思念 提交于 2021-02-10 06:56:16
问题 Consider the following small function: void foo(int* iptr) { iptr[10] = 1; __asm__ volatile ("nop"::"r"(iptr):); iptr[10] = 2; } Using gcc, this compiles to: foo: nop mov DWORD PTR [rdi+40], 2 ret Note in particular, that the first write to iptr , iptr[10] = 1 doesn't occur at all: the inline asm nop is the first thing in the function, and only the final write of 2 appears (after the ASM call). Apparently the compiler decides that it only needs to provide an up-to-date version of the value of

IRQ symbol defined in static library does not override weak IRQ definition from ARM/GCC startup

大憨熊 提交于 2021-02-10 06:42:26
问题 I have built a static library (*.a for gcc, *.lib for keil). One of its source file, compiled into library, contains definition of RADIO_IRQHandler. An excerpt from this source file, called "ral_irq_handlers.c", is below: ... void ral_symbol_import(void) //dummy function { return; } ... void RADIO_IRQHandler(void) { ... } ... This IRQ symbol definition should override the weak definition which is declared in startup file. The startup file is not compiled into any static library and is just a

Number of machine cycles required for RET instruction in 8085?

夙愿已清 提交于 2021-02-10 06:26:48
问题 How many number of machine cycles are required for the RET instruction in 8085? Why does it require that many number of cycles? 回答1: The RET instruction needs 3 machine cycles. One to fetch and decode the instruction (4 T states), and two more machine cycles (that is, 2*3 = 6 T states) to read two bytes from the stack (stack is exterior to microprocessor, stack is in read-write memory, so to exchange data with stack needs machine cycles). Thus, the RET instruction needs a total of 3 machine

Why am I allowed to exit main using ret?

杀马特。学长 韩版系。学妹 提交于 2021-02-10 05:14:20
问题 I am about to figure out how exactly a programm stack is set up. I have learned that calling the function with call pointer; Is effectively the same as: mov register, pc ;programcounter add register, 1 ; where 1 is one instruction not 1 byte ... push register jump pointer However, this would mean that when the Unix Kernel calls the main function that the stack base should point to reentry in the kernel function which calls main. Therefore jumping "*rbp-1" in the C - Code should reenter the

What do %pcrel_hi and %pcrel_lo actually do?

三世轮回 提交于 2021-02-10 05:12:47
问题 In Control and Status Registers section of riscv-asm-manual, there is an example: .equ RTC_BASE, 0x40000000 .equ TIMER_BASE, 0x40004000 # setup machine trap vector 1: auipc t0, %pcrel_hi(mtvec) # load mtvec(hi) addi t0, t0, %pcrel_lo(1b) # load mtvec(lo) csrrw zero, mtvec, t0 ... # break on interrupt mtvec: csrrc t0, mcause, zero bgez t0, fail # interrupt causes are less than zero slli t0, t0, 1 # shift off high bit ... I guess %pcrel_hi(mtvec) calculate the hi-distance between mtvec and