K
K
Kibakus2019-12-01 23:01:16
linux
Kibakus, 2019-12-01 23:01:16

How to write a program with the following algorithm (NASM assembler)?

1) display an invitation;
DONE
2) enter a string from the keyboard (it is assumed that it contains decimal digits and any letters);
DONE
3) find all the digits in the entered string and for each found digit set to "1" in the ax register the bit whose number is equal to this digit. Display the contents of the register ax in the form of zeros and ones;
NOT DONE
Sample program but I don't know how to make an algorithm for the task:
Please write assembly code Using NASM, LD, int 80h.

nasm -f elf -F dwarf -g file.asm
ld -m elf_i386 -o file file.o

SECTION .bss
    num:       resb 254
SECTION .data
    hello:     db 'Enter the string: ',0
    helloLen:  equ $-hello
    output:    db 'Output: ',0
    outputlen: equ $-output

SECTION .text
    GLOBAL _start

_start:
    mov eax,4
    mov ebx,1
    mov ecx,hello
    mov edx,helloLen
    int 80h

    mov eax,3
    mov ebx,0
    mov ecx,num
    mov edx,254
    int 80h

    ...
    ...
    ...

    mov eax,4
    mov ebx,1
    mov ecx, ...
    mov edx, ...

    mov eax,1
    mov ebx,0
    int 80h

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2019-12-02
@jcmvbkbc

I don't know how to make an algorithm for the task

what exactly is the difficulty?
is it clear how to do it?
if the value of the digit is known, then the mask for the desired bit can be obtained by applying the shl instruction to 1. The mask can be added to the value of the register with the or instruction.
check the least significant bit of the register (or the most significant one, if you want to output bits from high to low), output 0 or 1, shift the register to the right (or, respectively, to the left). repeat 16 times.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question