gas

x86 assembler: floating point compare

对着背影说爱祢 提交于 2019-12-17 04:32:44
问题 As part of a compiler project I have to write GNU assembler code for x86 to compare floating point values. I have tried to find resources on how to do this online and from what I understand it works like this: Assuming the two values I want to compare are the only values on the floating point stack, then the fcomi instruction will compare the values and set the CPU-flags so that the je , jne , jl , ... instructions can be used. I'm asking because this only works sometimes. For example:

Code works on bochs but does not on real computer, x86 real mode

被刻印的时光 ゝ 提交于 2019-12-13 16:19:45
问题 This small piece of code works fine on bochs 2.6, but doesn't seem to work on 'real' computers (I've tried several of them). It seems like lodsb is causing the problem, since it worked fine, when I did hello world by printing the string "manually" character by character. .code16 .text .globl _start _start: movw $0, %ax jmp main ### DATA AND BUFFERS ### welcome: .asciz "welcome" main: movw $welcome, %si call print_string hang: jmp hang print_string: lodsb cmp $0, %al je done mov $0x0e, %ah int

Using .org directive with data in .data section: In connection with ld

穿精又带淫゛_ 提交于 2019-12-13 14:33:00
问题 In my efforts to understand how to use the GNU binutils to build a simple boot loader using gas I have come across the question, how do you tell the linker where to put your data, in a file that uses .org to advance the location counter while keeping the file size at 512 bytes. I can't seem to find a way to do this. The assembly program that tries to do this is: # Author: Matthew Hoggan # Date Created: Tuesday, Mar 6, 2012 .code16 # Tell assembler to work in 16 bit mode .section .data msg: #

why cannot define same local label in multiple functions?

无人久伴 提交于 2019-12-12 18:54:56
问题 Want to define same local label in multiple functions: .text .globl main func: push %rbp mov %rsp, %rbp .a: leave ret main: push %rbp mov %rsp, %rbp .a: leave ret Strangely get error: $ clang -c main.s main.s:13:1: error: invalid symbol redefinition .a: ^ When I was using yasm it allowed same local labels in multiple functions. Do you have any clues? 回答1: Unlike NASM, .label isn't local to the function (actually preceding non- . label) in gas syntax. .Llabel is a "local" symbol name, meaning

When is it better for an assembler to use sign extended relocation like R_X86_64_32S instead of zero extension like R_X86_64_32?

久未见 提交于 2019-12-12 17:14:47
问题 As a concrete example, on GAS 2.24, moving the address: mov $s, %eax s: After: as --64 -o a.o a.S objdump -Sr a.o Uses zero extension: 0000000000000000 <s-0x5>: 0: b8 00 00 00 00 mov $0x0,%eax 1: R_X86_64_32 .text+0x5 But memory access: mov s, %eax s: Compiles to sign extension: 0000000000000000 <s-0x7>: 0: 8b 04 25 00 00 00 00 mov 0x0,%eax 3: R_X86_64_32S .text+0x7 Is there a rationale to using either in this specific case, or in general? I don't understand how the assembler could to any

GNU assembler did not produce a program that I can execute

天涯浪子 提交于 2019-12-12 10:14:03
问题 I tried assembling some intermediate code generated by gcc. I used the command as -o hello hello.s , which, as far as I can tell, is the correct syntax. When I tried to run the program, it said bash: ./hello: cannot execute binary file . It doesn't seem like there's a problem with the assembly code, since it was the code generated by gcc, and it doesn't seem like there's anything wrong with how I invoked the assembler, since that seems to be the right syntax according to this manual. Can

can't open Slack dialog through google apps scripts

好久不见. 提交于 2019-12-12 08:57:26
问题 I'm trying to use google apps scripts and slack to automate my work. And I wish to enter some text with the Slack dialog to modify my google spreadsheet with google apps scripts. However, with the below code, I can't open a Dialog via Slack-API's Slash command . Is my code have some problems? function doPost(e){ var params = e.parameter; var token = params.token; var text = params.text; var trigger_id = params.trigger_id; var slackUrl = ["https://slack.com/api/dialog.open"]; if (token == "

gas vs. nasm: which assembler produces the best code?

萝らか妹 提交于 2019-12-12 07:53:58
问题 Both tools translate assembly instructions directly into machine code, but is it possible to determine which one produces the fastest and cleanest code? 回答1: When you're writing in assembler, you are precisely describing the instructions to generate so it doesn't depend on the assembler. It depends on you. There's a one-to-one correspondence between the mnemonics you write and actual instructions in machine code. 回答2: I don't know about these two specific tools, but there are some

Use of ifdef in gas assembly language

怎甘沉沦 提交于 2019-12-12 05:38:58
问题 I have following assembly file mov.s .text .macro test_3 and $3,%eax .endm movz: movzb %al,%ax movzb (%eax),%ax movzb %al,%eax movzb (%eax),%eax .ifdef test_3 movzb33 %al,%rax movzb (%rax),%rax .endif command as -o dump.o movz In this code I want to test ifdef in assembly language so I have defined macro test_3. According to my understanding it should print message Error: no such instruction: 'movzb33 %al,%rax' when I use assembler but it is not going inside ifdef so what is the problem? 回答1:

C Function Call Convention: Why movl instead of pushl?

帅比萌擦擦* 提交于 2019-12-12 02:44:39
问题 I don't understand why the following lines are using movl to push data below the stack pointer are produced by GCC. movl -4(%ebp), %eax # -4(%ebp) <- local variable 1 movl 8(%ebp), %edx # 8(%ebp) <- first parameter movl %edx, 8(%esp) # ??? WHY NOT: pushl %edx movl %eax, 4(%esp) # ??? WHY NOT: pushl %eax movl -8(%ebp), %eax # ??? WHY NOT: pushl -8(%ebp) movl %eax, (%esp) call athena movl %eax, f (full code) I guess this code tries to push 3 parameters for the function call. But why isn't it