首页 > 解决方案 > 为什么我在 x86 中收到核心转储错误?

问题描述

# module for getMonthYear(char *buffer, int mon, int year)

    .global getMonthYear
    .type getMonthYear, @function

    .data

    .text
# TODO - put strings here
rdi:
    .string "January\n"
rsi:
    .string "February\n"
rdx:
    .string "March\n"
rcx:
    .string "April\n"
r8:
    .string "May\n"
r9:
    .string "June\n"
r10:
    .string "July\n"
r11:
    .string "August\n"
r12:
    .string "September\n"
r13:
    .string "October\n"
r14:
    .string "November\n"
r15:
    .string "December\n"
rsp:
    .string "Not valid month\n"

getMonthYear:
    push %rbp
    mov %rsp, %rbp

    # TODO
    cmp $1, %rax
    je case_1
    cmp $2, %rax
    je case_2
    cmp $3, %rax
    je case_3
    cmp $4, %rax
    je case_4
    cmp $5, %rax
    je case_5
    cmp $6, %rax
    je case_6
    cmp $7, %rax
    je case_7
    cmp $8, %rax
    je case_8
    cmp $9, %rax
    je case_9
    cmp $10, %rax
    je case_10
    cmp $11, %rax
    je case_11
    cmp $12, %rax
    je case_12
    jmp case_default

case_1:
    mov %rdi, %rax
    ret
case_2:
    mov %rsi, %rax
    ret
case_3:
    mov %rdx, %rax
    ret
case_4:
    mov %rcx, %rax
    ret
case_5:
    mov %r8, %rax
    ret
case_6:
    mov %r9, %rax
    ret
case_7:
    mov %r10, %rax
    ret
case_8:
    mov %r11, %rax
    ret
case_9:
    mov %r12, %rax
    ret
case_10:
    mov %r13, %rax
    ret
case_11:
    mov %r14, %rax
    ret
case_12:
    mov %r15, %rax
    ret
case_default:
    mov %rsp, %rax
    ret


    pop %rbp
    ret

标签: assemblyx86att

解决方案


推荐阅读