nasm

strlen in assembly

吃可爱长大的小学妹 提交于 2019-12-23 10:28:09
问题 I made my own implementation of strlen in assembly, but it doesn't return the correct value. It returns the string length + 4. Consequently. I don't see why.. and I hope any of you do... Assembly source: section .text [GLOBAL stringlen:] ; C function stringlen: push ebp mov ebp, esp ; setup the stack frame mov ecx, [ebp+8] xor eax, eax ; loop counter startLoop: xor edx, edx mov edx, [ecx+eax] inc eax cmp edx, 0x0 ; null byte jne startLoop end: pop ebp ret And the main routine: #include <stdio

Printf without newline in assembly

戏子无情 提交于 2019-12-23 09:39:08
问题 I've recently read this article on using printf and scanf in assembly: Meaning of intfmt: db "%d", 10, 0 in assembly In particular it says "In printf, the newline prints a newline and then (if the output is in line buffered mode, which it probably is), flushes the internal output buffer so you can actually see the result. So when you remove the 10, there's no flush and you don't see the output." However I do not know what to do if I do not want a newline after my output in my assembly file.

nasm random number generator function [duplicate]

徘徊边缘 提交于 2019-12-23 05:29:14
问题 This question already has answers here : Randomizing Numbers in Assembly with MASM32 (3 answers) Closed last year . I need a random number generator function written in nasm. I'm sorry for asking, but I couldn't find any! 回答1: In many cases a call to rdtsc is enough. Anyway, it depends on your needs. It's perfect when you need a small random number rarely: rdtsc % N , or as seed for more complicate algorithms for other cases. 回答2: Among other things, Agner Fog has a random number generator

NASM: how to access ssd drive correctly?

。_饼干妹妹 提交于 2019-12-23 04:49:06
问题 I need to access SSD drive with NASM 16-bit code. When accessing regular hard drive, need to set registers AX, DX, CX to choose Cylinder/Track/Sector/Number of sectors ( AH - to choose read sector function, DL - to choose drive number, CH - to choose cylinder, DH - to choose side on disk, CL - to choose sector on track, AL - to choose number of sectors). However, I suppose SSD disk has some other structure, so how to access them correctly? 回答1: Assuming translation of fake geometry into LBA

What's wrong with following assembly code?

怎甘沉沦 提交于 2019-12-23 04:45:41
问题 code to take input string assemble using nasm on windows machine: nasm file.asm -o file.com ;read the string mov ah,0x0A ;read mov dx,buffer ;pointer to buffer int 0x21 ;newline mov ah,2 mov dl,10 int 0x21 mov dl,13 int 0x21 ;put $ sign at end of string mov bx,buffer+1 mov dx,buffer+2 add dl,byte[bx] mov bx,dx mov byte[bx],'$' ;output mov dx,buffer+2 mov ah,9 int 0x21 ;exit mov ah,0x4c int 0x21 ;buffer buffer: db 255 ;len of buffer db 0 ;num of char read db 255 ;actual string ;###############

X86 NASM Assembly converting lower to upper and upper to lowercase characters

邮差的信 提交于 2019-12-23 03:49:14
问题 As i am pretty new to assembly, i have a few questions in regards to how i should convert from a lowercase to an uppercase if the user enters an uppercase letter or vice versa in assembly. here is what i have so far: section .data Enter db "Enter: " Enter_Len equ $-Enter Output db "Output: " Output_Len equ $-Output Thanks db "Thanks!" Thanks_Len equ $-Thanks Loop_Iter dd 0 ; Loop counter section .bss In_Buffer resb 2 In_Buffer_Len equ $-In_Buffer section .text global _start _start: ; Print

Shellcode with restrictions

拈花ヽ惹草 提交于 2019-12-23 02:54:08
问题 For a task I need to create simple shellcode, but it is not allowed that it contains \x80. Notice: To make a system call on linux, like write or exit, you need among others this line: int 0x80 , which in the end will produce shellcode including \x80. Nevertheless I need to make system calls, so my idea now is to use a variable for the interrupt vector number. For example 0x40 and then multiply it with 2, so in the end there will be a \x40 but not a \x80 in the shellcode. The problem is that

How 'push imm' encodes?

☆樱花仙子☆ 提交于 2019-12-22 13:17:11
问题 The << Intel 64 and IA-32 Architectures Software Developer’s Manual Volume 2B: Instruction Set Reference, N-Z >> says: | Opcode* | Instruction | Op/En | 64-Bit Mode | Compat/Leg Mode | Description | | 6A | PUSH imm8 | C | Valid | Valid | Push imm8. | | 68 | PUSH imm16 | C | Valid | Valid | Push imm16. | | 68 | PUSH imm32 | C | Valid | Valid | Push imm32. | # cat -n test.asm 1 bits 64 2 3 push byte 12 4 push word 12 5 push dword 12 6 push qword 12 7 # nasm test.asm test.asm:5: error:

linux nasm move a value in AL up to AX

十年热恋 提交于 2019-12-22 10:45:30
问题 I am working on a way to print multiple digit integers by dividing the integer by 10 repeatedly and collecting the remainders, then printing them. Here is a code segment that has the problem: Divide: ; initial division mov ax, 111 ; number we want to print mov ch, 10 ; we divide by ten to siphon digits div ch ; divide our number by 10 ; al now has 11, ah has 1 mov dh, ah ; save the remainder in dh 1 mov bx, al ; these lines refill ax with the number to mov ax, bx ; divide mov ch, 10 ; refill

Mach-O 64-bit format does not support 32-bit absolute addresses. NASM [duplicate]

拥有回忆 提交于 2019-12-22 08:17:02
问题 This question already has answers here : x64 nasm: pushing memory addresses onto the stack & call function (3 answers) Mach-O 64-bit format does not support 32-bit absolute addresses. NASM Accessing Array (1 answer) Closed last year . When I use nasm -f macho64 asm1.asm I get the following error: asm1.asm:14: error: Mach-O 64-bit format does not support 32-bit absolute addresses This is asm1.asm SECTION .data ;initialized data msg: db "Hello world, this is assembly", 10, 0 SECTION .text ;asm