RUVIDEO
Поделитесь видео 🙏

Get largest number from array using index backward , Learn to Program with Assembly

Playlist
https://www.youtube.com/playlist?list=PLIpLw6v7Z1qmiclRNOgxObV73eXpshzTb

2023 10 15 13 19 57


guage allows us to think about programs differently and optimize them so that
the program follows the thinking patterns of the computer. The instruction set we are
working with likes to count down to zero (because of the loop family of instructions). We
normally think about going from the start of the array to the end, but what if we went the
other way? What if we went from the end of the array back to the beginning?
In this case, %rcx could do double duty as both the counter and the index! This
removes two instructions from the code, one of which is in our loop.
The only problem with this is that %rcx would be an index from 1 to 7, while
our previous index (%rbx) was from 0 to 6. Therefore, we will have to subtract 8 (one
quadword) from the value (mynumbers) to account for this. That’s okay, because the
assembler knows how to do this and will do it for us.
70
Chapter 6 Working with Data in Memory
The code for this is as follows:
largestvaluercx.s
.globl _start
.section .data
# How many data elements we have
numberofnumbers:
.quad 7
# The data elements themselves
mynumbers:
.quad 5, 20, 33, 80, 52, 10, 1
### This program will find the largest value in the array
.section .text
_start:
### Initialize Registers ###
# Put the number of elements of the array in %rcx
movq numberofnumbers, %rcx
# Use %rdi to hold the current-high value
movq $0, %rdi
### Check Preconditions ###
# If there are no numbers, stop
cmp $0, %rcx
je endloop
### Main Loop ###
myloop:
# Get the next value of mynumbers indexed by %rbx
movq mynumbers-8(,%rcx,8), %rax
# If it is not bigger, go to the end of the loop
cmp %rdi, %rax
71
Chapter 6 Working with Data in Memory
jbe loopcontrol
# Otherwise, store this as the biggest element so far
movq %rax, %rdi
loopcontrol:
# Decrement %rcx and keep going until %rcx is zero
loopq myloop
### Cleanup and Exit ###
endloop:
# We're done - exit
movq $60, %rax
syscall
As mentioned, the address lookup was modified to be movq mynumbers-8(,%rcx,8),
%rax. So, since mynumbers is known by the assembler (it is whatever address the
assembler assigns to that data), the assembler can also subtract 8 and encode that
number into the instruction. The subtraction here is not done by the CPU when it runs,
it is done at the time of assembly. Again, the reason for this is that, unlike the previous
program, %rcx is going to be 1 through 7, not 0 through 6. Therefore, if we didn’t adjust it,
it would start at the second element and run past the end of the array.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Get largest number from array using index backward , Learn to Program with Assembly», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.