小编Fro*_*and的帖子

NASM Linux程序集打印整数

我试图在linux上的nasm程序集中打印单个数字整数.我目前编写的内容很好,但没有任何内容写入屏幕.任何人都可以向我解释我在这里做错了什么吗?

section .text
    global _start

_start:
    mov ecx, 1          ; stores 1 in rcx
    add edx, ecx        ; stores ecx in edx
    add edx, 30h        ; gets the ascii value in edx
    mov ecx, edx        ; ascii value is now in ecx
    jmp write           ; jumps to write


write:
    mov eax, ecx        ; moves ecx to eax for writing
    mov eax, 4          ; sys call for write
    mov ebx, 1          ; stdout

    int 80h             ; call kernel
    mov eax,1           ; …
Run Code Online (Sandbox Code Playgroud)

linux assembly nasm

6
推荐指数
2
解决办法
8807
查看次数

赢得连接4类似游戏的条件

我有一个5x10数组,其中填充了随机值1-5.我希望能够检查3个数字(水平或垂直)是否匹配.如果不写大量的if语句,我无法想出办法.

这是随机填充的数组的代码


int i;
int rowincrement = 10;
int row = 0;
int col = 5;
int board[10][5];
int randomnum = 5;


int main(int argc, char * argv[])
{
    srand(time(NULL));

    cout << "============\n";

    while(row < rowincrement)
    {

        for(i = 0; i < 5; i++)
        {
            board[row][col] = rand()%5 + 1; 
            cout << board[row][col] << " ";
        }
        cout << endl;
        cout << "============\n";
        row++;
    }
    cout << endl;
    return 0;
}

c++ arrays

3
推荐指数
1
解决办法
9108
查看次数

用c ++对数组进行混洗

可能重复:
我应该如何为数组实现随机数或随机数算法以随机顺序显示引号?

我有一个小数组,我需要在数组中随机改组.我可以使用random.shuffle()在python中执行此操作,但我似乎可以弄清楚如何在C++中执行此操作.

这是python中我想用C++做的一个例子


#!/usr/bin/python

import random

array = [1,2,3,4,5]

random.shuffle(array)

print array

c++ python

1
推荐指数
1
解决办法
1191
查看次数

为什么这个char数组Seg Fault

任何人都可以向我解释为什么在初始化一个char数组时,如果数组大小留空,就像这样

char str1[] = "Hello";
Run Code Online (Sandbox Code Playgroud)

程序会出现故障,但如果是这样指定的话

char str1[10] = "Hello";
Run Code Online (Sandbox Code Playgroud)

它工作正常.

这是完整的计划

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char concat_string(char str[], char str2[], char destination[], unsigned int bufferSize);

int main(int argc, char *argv[])
{
    unsigned int bufferSize = 64;
    // Both str1 and str2 must be defined
    // or else the program will seg fault.
    char str1[] = "Hello ";
    char str2[] = "World";
    char concatenatedString[bufferSize];

    concat_string(str1,str2,concatenatedString,bufferSize);

    printf("The concatenated string is: \n%s\n", concatenatedString);
    return 0;
}


char concat_string(char str[], char …
Run Code Online (Sandbox Code Playgroud)

c arrays char segmentation-fault

0
推荐指数
1
解决办法
1313
查看次数

标签 统计

arrays ×2

c++ ×2

assembly ×1

c ×1

char ×1

linux ×1

nasm ×1

python ×1

segmentation-fault ×1