assembly

Manipulating Strings in Assembly (MASM)

前提是你 提交于 2021-02-16 21:59:14
问题 .data source BYTE "Defense mechanism",0 target BYTE SIZEOF source DUP(0) .code main PROC mov esi, OFFSET target mov edi, OFFSET target mov ecx, SIZEOF source L1: mov al,[esi] ; get a character from source mov [edi],al ; store it in the target inc esi ; move to next character inc edi loop L1 In the .data section, I see that source is defined as the string. In the .code section, I see that the memory location of target is stored in the source index. Shouldn't I want the source index ( ESI ) to

How is a GDT invoked?

血红的双手。 提交于 2021-02-16 21:50:36
问题 I know how a GDT (Global Descriptor Table) is implemented and the use of segment registers and segment descriptors. However how/when is a GDT entry accessed? Is it accessed in basic mov instructions like mov [eax],ebx Does this implicitly invoke ds segment register and then access the GDT segment descriptor or there is some other way via which access to the GDT entry happens? 回答1: TL;DR : The Global Descriptor Table (GDT) or Local Descriptor Table (LDT) is only accessed when a segment

How is a GDT invoked?

北城余情 提交于 2021-02-16 21:49:25
问题 I know how a GDT (Global Descriptor Table) is implemented and the use of segment registers and segment descriptors. However how/when is a GDT entry accessed? Is it accessed in basic mov instructions like mov [eax],ebx Does this implicitly invoke ds segment register and then access the GDT segment descriptor or there is some other way via which access to the GDT entry happens? 回答1: TL;DR : The Global Descriptor Table (GDT) or Local Descriptor Table (LDT) is only accessed when a segment

how do i rotate a value in assembly

一世执手 提交于 2021-02-16 20:40:38
问题 I am implementing a function in assembly x86 64 bits, which I am unable to alter: unsigned long rotate(unsigned long val, unsigned long num, unsigned long direction); direction- 1 is left and 0 is right. This is my code to shift left but its not working the last bit is off. Can someone help me please. rotate: push rbp push rdi push rsi push rdx mov rbp, rsp sub rsp, 16 cmp rdx, 1 je shift_left shift_left: mov rax, rdi shl rax, cl mov rax, rax mov rcx, rdi sub cl, 64 shl rcx, cl or rax rdx mov

how do i rotate a value in assembly

旧巷老猫 提交于 2021-02-16 20:40:28
问题 I am implementing a function in assembly x86 64 bits, which I am unable to alter: unsigned long rotate(unsigned long val, unsigned long num, unsigned long direction); direction- 1 is left and 0 is right. This is my code to shift left but its not working the last bit is off. Can someone help me please. rotate: push rbp push rdi push rsi push rdx mov rbp, rsp sub rsp, 16 cmp rdx, 1 je shift_left shift_left: mov rax, rdi shl rax, cl mov rax, rax mov rcx, rdi sub cl, 64 shl rcx, cl or rax rdx mov

Can't get output of assembly language code

别说谁变了你拦得住时间么 提交于 2021-02-16 20:30:17
问题 I am newbie in assembly language. I am trying to get a string of numbers from user terminated by Enter or the length of the string reaching 20. When I executed the program it didn't show any error, but neither did it show any output nor did it terminate when the string exceeded the 20 characters limit. My code is: .model small .stack 100h .data var1 db 100 dup('$') .code main proc mov ax, @data mov dx, ax mov si, offset var1 l1: mov ah, 1 int 21h cmp al,20 je programend mov [si], al inc si

Can't get output of assembly language code

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-16 20:29:06
问题 I am newbie in assembly language. I am trying to get a string of numbers from user terminated by Enter or the length of the string reaching 20. When I executed the program it didn't show any error, but neither did it show any output nor did it terminate when the string exceeded the 20 characters limit. My code is: .model small .stack 100h .data var1 db 100 dup('$') .code main proc mov ax, @data mov dx, ax mov si, offset var1 l1: mov ah, 1 int 21h cmp al,20 je programend mov [si], al inc si

Should %rsp be aligned to 16-byte boundary before calling a function in NASM?

社会主义新天地 提交于 2021-02-16 20:20:22
问题 I saw the following rules from NASM's document: The stack pointer %rsp must be aligned to a 16-byte boundary before making a call. Fine, but the process of making a call pushes the return address (8 bytes) on the stack, so when a function gets control, %rsp is not aligned. You have to make that extra space yourself, by pushing something or subtracting 8 from %rsp. And I have a snippet of NASM assembly code as below: The %rsp should be at the boundary of 8-bytes before I call the function "inc

Using scanf into global or local variables (on the stack), 32-bit calling convention

好久不见. 提交于 2021-02-16 20:11:49
问题 Given the following code : .section .rodata str: .string "Hello World!\n" input: .long 2 ######## .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp pushl $str call printf #return from printf: movl $0, %eax movl %ebp,%esp popl %ebp ret The output would be "Hello World!". Now I try to get a number from the user , and then print it out on the screen , but it doesn't work (code compile,but I did something wrong) . Where is my mistake ? .section .rodata input: .long 2 ######

Using scanf into global or local variables (on the stack), 32-bit calling convention

邮差的信 提交于 2021-02-16 20:11:12
问题 Given the following code : .section .rodata str: .string "Hello World!\n" input: .long 2 ######## .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp pushl $str call printf #return from printf: movl $0, %eax movl %ebp,%esp popl %ebp ret The output would be "Hello World!". Now I try to get a number from the user , and then print it out on the screen , but it doesn't work (code compile,but I did something wrong) . Where is my mistake ? .section .rodata input: .long 2 ######