.file "main.cpp" .text .section .rodata .type _ZStL19piecewise_construct, @object .size _ZStL19piecewise_construct, 1 _ZStL19piecewise_construct: .zero 1 .local _ZStL8__ioinit .comm _ZStL8__ioinit,1,1 .LC0: .string "Enter first value:" .LC1: .string "Enter second value:" .section .text._ZN9operation3getEv,"axG",@progbits,_ZN9operation3getEv,comdat .align 2 .weak _ZN9operation3getEv .type _ZN9operation3getEv, @function _ZN9operation3getEv: .LFB1522: .cfi_startproc endbr64 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $16, %rsp movq %rdi, -8(%rbp) leaq .LC0(%rip), %rsi leaq _ZSt4cout(%rip), %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT movq -8(%rbp), %rax movq %rax, %rsi leaq _ZSt3cin(%rip), %rdi call _ZNSirsERi@PLT leaq .LC1(%rip), %rsi leaq _ZSt4cout(%rip), %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT movq -8(%rbp), %rax addq $4, %rax movq %rax, %rsi leaq _ZSt3cin(%rip), %rdi call _ZNSirsERi@PLT nop leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1522: .size _ZN9operation3getEv, .-_ZN9operation3getEv .section .rodata .LC2: .string "Addition of two numbers: " .LC3: .string "\n" .section .text._ZN9operation3sumEv,"axG",@progbits,_ZN9operation3sumEv,comdat .align 2 .weak _ZN9operation3sumEv .type _ZN9operation3sumEv, @function _ZN9operation3sumEv: .LFB1523: .cfi_startproc endbr64 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $16, %rsp movq %rdi, -8(%rbp) movq -8(%rbp), %rax movl (%rax), %edx movq -8(%rbp), %rax movl 4(%rax), %eax addl %eax, %edx movq -8(%rbp), %rax movl %edx, 8(%rax) leaq .LC2(%rip), %rsi leaq _ZSt4cout(%rip), %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT movq %rax, %rdx movq -8(%rbp), %rax movl (%rax), %ecx movq -8(%rbp), %rax movl 4(%rax), %eax addl %ecx, %eax movl %eax, %esi movq %rdx, %rdi call _ZNSolsEi@PLT leaq .LC3(%rip), %rsi movq %rax, %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT nop leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1523: .size _ZN9operation3sumEv, .-_ZN9operation3sumEv .section .rodata .LC4: .string "Difference of two numbers: " .section .text._ZN9operation10differenceEv,"axG",@progbits,_ZN9operation10differenceEv,comdat .align 2 .weak _ZN9operation10differenceEv .type _ZN9operation10differenceEv, @function _ZN9operation10differenceEv: .LFB1524: .cfi_startproc endbr64 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $16, %rsp movq %rdi, -8(%rbp) movq -8(%rbp), %rax movl (%rax), %edx movq -8(%rbp), %rax movl 4(%rax), %eax subl %eax, %edx movq -8(%rbp), %rax movl %edx, 12(%rax) leaq .LC4(%rip), %rsi leaq _ZSt4cout(%rip), %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT movq %rax, %rdx movq -8(%rbp), %rax movl (%rax), %ecx movq -8(%rbp), %rax movl 4(%rax), %eax subl %eax, %ecx movl %ecx, %eax movl %eax, %esi movq %rdx, %rdi call _ZNSolsEi@PLT leaq .LC3(%rip), %rsi movq %rax, %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT nop leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1524: .size _ZN9operation10differenceEv, .-_ZN9operation10differenceEv .section .rodata .LC5: .string "Product of two numbers: " .section .text._ZN9operation7productEv,"axG",@progbits,_ZN9operation7productEv,comdat .align 2 .weak _ZN9operation7productEv .type _ZN9operation7productEv, @function _ZN9operation7productEv: .LFB1525: .cfi_startproc endbr64 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $16, %rsp movq %rdi, -8(%rbp) movq -8(%rbp), %rax movl (%rax), %edx movq -8(%rbp), %rax movl 4(%rax), %eax imull %eax, %edx movq -8(%rbp), %rax movl %edx, 16(%rax) leaq .LC5(%rip), %rsi leaq _ZSt4cout(%rip), %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT movq %rax, %rdx movq -8(%rbp), %rax movl (%rax), %ecx movq -8(%rbp), %rax movl 4(%rax), %eax imull %ecx, %eax movl %eax, %esi movq %rdx, %rdi call _ZNSolsEi@PLT leaq .LC3(%rip), %rsi movq %rax, %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT nop leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1525: .size _ZN9operation7productEv, .-_ZN9operation7productEv .section .rodata .LC6: .string "Division of two numbers: " .section .text._ZN9operation8divisionEv,"axG",@progbits,_ZN9operation8divisionEv,comdat .align 2 .weak _ZN9operation8divisionEv .type _ZN9operation8divisionEv, @function _ZN9operation8divisionEv: .LFB1526: .cfi_startproc endbr64 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $16, %rsp movq %rdi, -8(%rbp) movq -8(%rbp), %rax movl (%rax), %eax movq -8(%rbp), %rdx movl 4(%rdx), %ecx cltd idivl %ecx cvtsi2ssl %eax, %xmm0 movq -8(%rbp), %rax movss %xmm0, 20(%rax) leaq .LC6(%rip), %rsi leaq _ZSt4cout(%rip), %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT movq %rax, %rcx movq -8(%rbp), %rax movl (%rax), %eax movq -8(%rbp), %rdx movl 4(%rdx), %esi cltd idivl %esi movl %eax, %esi movq %rcx, %rdi call _ZNSolsEi@PLT leaq .LC3(%rip), %rsi movq %rax, %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT nop leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1526: .size _ZN9operation8divisionEv, .-_ZN9operation8divisionEv .section .rodata .align 8 .LC7: .string "Program using inline function\n" .text .globl main .type main, @function main: .LFB1527: .cfi_startproc endbr64 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $32, %rsp movq %fs:40, %rax movq %rax, -8(%rbp) xorl %eax, %eax leaq .LC7(%rip), %rsi leaq _ZSt4cout(%rip), %rdi call _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT leaq -32(%rbp), %rax movq %rax, %rdi call _ZN9operation3getEv leaq -32(%rbp), %rax movq %rax, %rdi call _ZN9operation3sumEv leaq -32(%rbp), %rax movq %rax, %rdi call _ZN9operation10differenceEv leaq -32(%rbp), %rax movq %rax, %rdi call _ZN9operation7productEv leaq -32(%rbp), %rax movq %rax, %rdi call _ZN9operation8divisionEv movl $0, %eax movq -8(%rbp), %rdx xorq %fs:40, %rdx je .L8 call __stack_chk_fail@PLT .L8: leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1527: .size main, .-main .type _Z41__static_initialization_and_destruction_0ii, @function _Z41__static_initialization_and_destruction_0ii: .LFB2011: .cfi_startproc endbr64 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $16, %rsp movl %edi, -4(%rbp) movl %esi, -8(%rbp) cmpl $1, -4(%rbp) jne .L11 cmpl $65535, -8(%rbp) jne .L11 leaq _ZStL8__ioinit(%rip), %rdi call _ZNSt8ios_base4InitC1Ev@PLT leaq __dso_handle(%rip), %rdx leaq _ZStL8__ioinit(%rip), %rsi movq _ZNSt8ios_base4InitD1Ev@GOTPCREL(%rip), %rax movq %rax, %rdi call __cxa_atexit@PLT .L11: nop leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE2011: .size _Z41__static_initialization_and_destruction_0ii, .-_Z41__static_initialization_and_destruction_0ii .type _GLOBAL__sub_I_main, @function _GLOBAL__sub_I_main: .LFB2012: .cfi_startproc endbr64 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl $65535, %esi movl $1, %edi call _Z41__static_initialization_and_destruction_0ii popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE2012: .size _GLOBAL__sub_I_main, .-_GLOBAL__sub_I_main .section .init_array,"aw" .align 8 .quad _GLOBAL__sub_I_main .hidden __dso_handle .ident "GCC: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0" .section .note.GNU-stack,"",@progbits .section .note.gnu.property,"a" .align 8 .long 1f - 0f .long 4f - 1f .long 5 0: .string "GNU" 1: .align 8 .long 0xc0000002 .long 3f - 2f 2: .long 0x3 3: .align 8 4:
Write, Run & Share Assembly code online using OneCompiler's Assembly online compiler for free. It's one of the robust, feature-rich online compilers for Assembly language. Getting started with the OneCompiler's Assembly compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Assembly
and start coding.
Assembly language(asm) is a low-level programming language, where the language instructions will be more similar to machine code instructions.
Every assembler may have it's own assembly language designed for a specific computers or an operating system.
Assembly language requires less execution time and memory. It is more helful for direct hardware manipulation, real-time critical applications. It is used in device drivers, low-level embedded systems etc.
Assembly language usually consists of three sections,
Data section
To initialize variables and constants, buffer size these values doesn't change at runtime.
bss section
To declare variables
text section
_start
specifies the starting of this section where the actually code is written.
There are various define directives to allocate space for variables for both initialized and uninitialized data.
variable-name define-directive initial-value
Define Directive | Description | Allocated Space |
---|---|---|
DB | Define Byte | 1 byte |
DW | Define Word | 2 bytes |
DD | Define Doubleword | 4 bytes |
DQ | Define Quadword | 8 bytes |
DT | Define Ten Bytes | 10 bytes |
Define Directive | Description |
---|---|
RESB | Reserve a Byte |
RESW | Reserve a Word |
RESD | Reserve a Doubleword |
RESQ | Reserve a Quadword |
REST | Reserve a Ten Bytes |
Constants can be defined using
CONSTANT_NAME EQU regular-exp or value
%assign constant_name value
%define constant_name value
Loops are used to iterate a set of statements for a specific number of times.
mov ECX,n
L1:
;<loop body>
loop L1
where n specifies the no of times loops should iterate.
Procedure is a sub-routine which contains set of statements. Usually procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
procedure_name:
;procedure body
ret