The task is to write a macro for sampling from a certain array of decimal numbers of increased accuracy in the unpacked format of all elements with a given value of parity. Using this macro, process two arrays, in the first of which there are 100 20-bit numbers, and in the second - 50 30-bit numbers. In this case, from the first array, select numbers with even parity, and from the second with odd parity.

The data looks like this:

Var DB 2,2,3,3,4,4,5,5,6,6; 2233445566 десятичное 10-ти значное число 

To calculate the parity, it is necessary to convert the number system to 16 (I do not know of any other way). How to translate this number? MASM is used for a processor similar to Intel8086 (16-bit)

  • one
    And what is parity in your case? - KoVadim
  • And what is a "macro"? If the macro (which is doubtful), then you need to clarify what kind of assembler is used, everywhere the macros are different. - PinkTux
  • @KoVadim that's it, it is not known what parity is for 10 numbers, but for 16 it is known, but if I explain to you somewhere, what I say is not right and it will confuse you =) The main difficulty is to translate into 16 views, and then it's easy - helldrg
  • Will confuse me? Maybe all the same give a link? - KoVadim
  • @PinkTux I added in the question about the assembler and processor. Macro used: abc macros x, y, n, paritet ..... abc endm. Something like this - helldrg

1 answer 1

Translate your numbers to binary representation. I collected nasm + gcc, but I think it is not a problem to alter it under another assembler (and bit depth). But note that the specified number of 16 digits does not fit. Or you also need to use 32-bit operations, or store the result in a pair of registers:

 ; ------------------------------------------ section .data decnum db 2,2,3,3,4,4,5,5,6,6 declen equ $ - decnum fmt db '%u', 0Ah, 0 ; ------------------------------------------ section .text extern printf global main main: ; тут храним результат xor edi, edi ; выборка разрядов - с конца mov esi, decnum + declen - 1 mov ecx, declen ; текущий показатель степени mov ebx, 1 convert_loop: movzx eax, BYTE [esi] ; если бы число задавалось не двоичными цифрами, а ; символами (decnum db '2233445566'), то здесь ; надо добавить: ; sub al, '0' mul ebx add edi, eax ; следующий разряд увеличиваем в 10 раз mov eax, 10 mul ebx xchg eax, ebx dec esi loop convert_loop ; двоичное представление в edi, проверяем: push edi push fmt call printf ; ура, вывело строку "2233445566" ; а стек после printf восстанавливать ; не обязательно, всё равно выходим mov eax, 1 xor ebx, ebx int 80h ; ---------------------------------------- 

Sum of number bits:

  ; число в ebx mov ebx, 8 ; количество разрядов: mov ecx, 32 ; результат: xor eax, eax parity_loop: shr ebx, 1 adc eax, 0 loop parity_loop 
  • Now I will try to collect for myself accomplish your goal in 15 minutes, thanks! - helldrg
  • At first glance, I would need for edi (in my case, for di) to do indirect addressing to the memory, to write down the result. After each iteration, shift [di + 1]. Whatever overflow occurs, the carry flag must be remembered and the ADC command used. Here, the campaign more than 15 minutes ((Unsubscribe soon - helldrg
  • It's just that everything fits in your register, but my task is 20 and 30 digit numbers - helldrg
  • @helldrg For 20-30 digits in the decimal system, you need the inverse double dabble algorithm. in principle is googling, though with difficulty - Mike
  • @PinkTux Thank you so much! The only thing that doesn’t work with the increase in the digit capacity is to correctly perform the addition operation in the cycle. If I don’t succeed, I’ll create another topic, I hope you will help =) - helldrg